Komodo-在程序暂停时监视变量并执行代码 [英] Komodo - watch variables and execute code while on pause in the program

查看:100
本文介绍了Komodo-在程序暂停时监视变量并执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio IDE中的c#,我可以随时暂停程序并观察其变量,检查我想要的内容.我注意到,使用Komodo IDE发生崩溃时,它停止了程序的运行,我可以做完全一样的事情.但是由于某种原因,当我手动暂停程序时尝试执行相同的操作时,似乎无法实现相同的目的.我是在做错什么,还是不可能?在后一种情况下,有人可以向我解释原因吗?是与IDE相关还是与Python相关?

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 and it stops the flow of the program, I can do exactly the same. But for some reason, it seems that when I try to do the same when I manually pause the program, the same cannot be achieved. Am I doing something wrong or it just isn't possible? In the later case, could anyone care to explain me why? Is it IDE related or Python related?

谢谢

edit:另一个问题,我该如何继续执行该程序?从我所看到的,在我调用code.interact(local = locals())之后,它的行为就像程序仍在运行,因此我无法单击运行"按钮,只能单击暂停"或关闭".

edit: Other question, how can I then continue the program? From what I see, after I call code.interact(local = locals()), it behaves as the program is still running so I can't click in the "Run" button, only on "Pause" or "Close".

推荐答案

如果您输入

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

在您的程序中,然后您将被转储到python解释器. (请参阅窥视当前正在运行的Python程序的方法)

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

这与暂停Komodo有点不同,但是也许您可以使用它来实现相同的目标.

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

按Ctrl-d退出python解释器,并允许您的程序继续运行.

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

像这样使用它:

@print_trace
def f():
    pass

这篇关于Komodo-在程序暂停时监视变量并执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆