Komodo - 在程序暂停时观察变量并执行代码

发布于 2024-08-10 18:01:06 字数 327 浏览 6 评论 0原文

通过 Visual Studio IDE 中的 C#,我可以随时暂停程序并观察其变量,检查我想要的任何内容。我注意到,使用 Komodo IDE,当出现崩溃并停止程序流程时,我可以执行完全相同的操作。但由于某种原因,似乎当我尝试在手动暂停程序时执行相同的操作时,无法实现相同的效果。我做错了什么或者这是不可能的吗?在后一种情况下,有人愿意解释我为什么吗?是IDE相关还是Python相关?

谢谢

编辑:其他问题,我怎样才能继续该程序?据我所知,在我调用 code.interact(local = locals()) 后,它的行为就像程序仍在运行一样,所以我无法单击“运行”按钮,只能单击“暂停”或“关闭”。

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?

Thanks

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2024-08-17 18:01:06

如果你输入

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

你的程序,那么你将被转储到 python 解释器。 (参见查看当前正在运行的Python程序的方法

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

按 Ctrl-d 退出 python 解释器并允许程序继续。

您可以使用回溯模块检查调用堆栈:

import traceback
traceback.extract_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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文