同时使用调试器和诅咒?
当异常触发时,我正在调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
詹姆斯的回答很好,我已经投票了,但我也会考虑尝试拆分程序的逻辑层和表示层。将curses 部分保留在库顶部的薄层,并编写一个简单的驱动程序来调用正确的例程来重新创建错误。然后您就可以潜入并做必要的事情。
我能想到的另一种方法是创建一个名为
debug
的函数,或者让您返回常规屏幕并调用 pdb 的函数。然后将其粘贴在引发异常的代码之前并运行您的程序。显然,这与使用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 likeApparently, this is similar to what is done with the
curses.wrapper
function. It's mentioned briefly at http://www.amk.ca/python/howto/curses/.由于不熟悉 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.
使用 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