同时使用调试器和诅咒?

发布于 2024-08-20 12:43:48 字数 133 浏览 3 评论 0原文

当异常触发时,我正在调用 python -m pdb myapp.py ,通常我会被扔回 pdb 解释器来调查问题。然而,在我通过curses.wrapper()调用并进入curses模式后,会抛出此异常,从而使pdb解释器无用。我该如何解决这个问题?

I'm calling python -m pdb myapp.py, when an exception fires, and I'd normally be thrown back to the pdb interpreter to investigate the problem. However this exception is being thrown after I've called through curses.wrapper() and entered curses mode, rendering the pdb interpreter useless. How can I work around this?

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

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

发布评论

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

评论(3

ヤ经典坏疍 2024-08-27 12:43:48

詹姆斯的回答很好,我已经投票了,但我也会考虑尝试拆分程序的逻辑层和表示层。将curses 部分保留在库顶部的薄层,并编写一个简单的驱动程序来调用正确的例程来重新创建错误。然后您就可以潜入并做必要的事情。

我能想到的另一种方法是创建一个名为 debug 的函数,或者让您返回常规屏幕并调用 pdb 的函数。然后将其粘贴在引发异常的代码之前并运行您的程序。显然

def debug(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
    import pdb; pdb.set_trace()

,这与使用curses.wrapper函数完成的操作类似。 http://www.amk.ca/python/howto/curses/。

James` answer is a good and I've upvoted it but I'd also consider trying to split the logic and presentation layers of my program. Keep the curses part a thin layer on top of a library and write a simple driver that invokes the correct routines to recreate the error. Then you can dive in and do what's necessary.

Another way I can think of is to create a function called debug or something that throws you back into the regular screen and invokes pdb. Then stick it just before the code that raises the exception and run your program. Something like

def debug(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
    import pdb; pdb.set_trace()

Apparently, this is similar to what is done with the curses.wrapper function. It's mentioned briefly at http://www.amk.ca/python/howto/curses/.

海未深 2024-08-27 12:43:48

由于不熟悉 Python,这可能不是您想要的。但显然,winpdb 可以附加到脚本 - 就像 gdb 可以附加到正在运行的进程 (IIUC) 一样。

http://winpdb.org/docs/launch-time/

不要被误导顾名思义,它是平台无关的。

Not being familiar with Python, this may not be exactly what you want. But apparently, winpdb can attach to a script - just like gdb can to a running process (IIUC).

http://winpdb.org/docs/launch-time/

Don't be mislead by the name, it is platform independent.

双手揣兜 2024-08-27 12:43:48

使用 pyclewn

您可以将 pyclewn 与 vim 一起使用。
或者使用 pdb-clone,pyclewn 的核心
很好,就像gdb一样,可以远程调试

use pyclewn

you can use pyclewn with vim.
or use pdb-clone,the core of pyclewn
its good ,its like gdb ,can remote debug

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