同时使用调试器和诅咒?

时间:2021-05-08 20:44:21

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?

我叫python -m pmydb应用。py,当一个异常触发时,我通常会被扔回pdb解释器以调查这个问题。但是,在我通过curses.wrapper()调用并进入curses模式之后,这个异常被抛出,使pdb解释器变得无用。我该怎么解决这个问题呢?

3 个解决方案

#1


8  

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.

詹姆斯的回答很好,我对此表示赞同,但我也会考虑拆分我的程序的逻辑和表示层。将curses部分放在一个库的顶部,并编写一个简单的驱动程序来调用正确的例程来重新创建错误。然后你就可以投入进去,做必要的事情。

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

我可以想到的另一种方法是创建一个名为debug的函数或将您扔回常规屏幕并调用pdb的东西。然后在引发异常并运行程序的代码之前执行它。类似的

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

显然,这类似于诅咒。包装器函数。在http://www.amk.ca/python/howto/curses/中有简单的介绍。

#2


7  

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

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

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

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

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

不要被名字误导,它是平*立的。

#3


0  

use pyclewn

使用pyclewn

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

你可以用pyclewn与vim。或者使用pdb-clone, pyclewn的核心特性,就像gdb一样,可以远程调试

#1


8  

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.

詹姆斯的回答很好,我对此表示赞同,但我也会考虑拆分我的程序的逻辑和表示层。将curses部分放在一个库的顶部,并编写一个简单的驱动程序来调用正确的例程来重新创建错误。然后你就可以投入进去,做必要的事情。

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

我可以想到的另一种方法是创建一个名为debug的函数或将您扔回常规屏幕并调用pdb的东西。然后在引发异常并运行程序的代码之前执行它。类似的

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

显然,这类似于诅咒。包装器函数。在http://www.amk.ca/python/howto/curses/中有简单的介绍。

#2


7  

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

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

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

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

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

不要被名字误导,它是平*立的。

#3


0  

use pyclewn

使用pyclewn

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

你可以用pyclewn与vim。或者使用pdb-clone, pyclewn的核心特性,就像gdb一样,可以远程调试