有没有办法将调试器附加到多线程的Python进程?
问题描述:
我试图在多线程Python应用程序锁定后调试死锁。有没有办法附加调试器来检查进程的状态?
I'm trying to debug a deadlock in a multi-threaded Python application after it has locked up. Is there a way to attach a debugger to inspect the state of the process?
编辑:我在Linux上尝试这样做,但如果有跨平台解决方案,那将是很棒的。毕竟是Python:)
I'm attempting this on Linux, but it would be great if there were a cross-platform solution. It's Python after all :)
答
是的,gdb对于较低级别的调试是有好处的。
Yeah, gdb is good for lower level debugging.
您可以使用线程命令更改线程。
You can change threads with the thread command.
例如
(gdb) thr 2
[Switching to thread 2 (process 6159 thread 0x3f1b)]
(gdb) backtrace
....
您还可以查看Python专用调试器,如 Winpdb 或 pydb 。两者平台独立。
You could also check out Python specific debuggers like Winpdb, or pydb. Both platform independent.