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

被刻印的时光 ゝ 提交于 2019-11-28 12:54:15
unutbu

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!