Komodo - watch variables and execute code while on pause in the program

前端 未结 1 382
清酒与你
清酒与你 2020-12-11 10:10

With c# in the Visual Studio IDE I can pause at anytime a program and watch its variables, inspect whatever I want. I noticed that with the Komodo IDE when something crashes

相关标签:
1条回答
  • 2020-12-11 11:13

    If you put

    import code
    code.interact(local=locals())
    

    in your program, then you will be dumped to a python interpreter. (See Method to peek at a Python program running right now)

    This is a little different than pausing Komodo, but perhaps you can use it to achieve the same goal.

    Pressing Ctrl-d exits the python interpreter and allows your program to resume.

    You can inspect the call stack using the traceback module:

    import traceback
    traceback.extract_stack()
    

    For example, here is a decorator which prints the call stack:

    def print_trace(func):
        '''This decorator prints the call stack
        '''
        def wrapper(*args,**kwargs):
            stacks=traceback.extract_stack()
            print('\n'.join(
                ['  '*i+'%s %s:%s'%(text,line_number,filename)
                 for i,(filename,line_number,function_name,text) in enumerate(stacks)]))
            res = func(*args,**kwargs)
            return res
        return wrapper
    

    Use it like this:

    @print_trace
    def f():
        pass
    
    0 讨论(0)
提交回复
热议问题