【发布时间】:2015-01-23 11:23:23
【问题描述】:
我想调试一个经常卡住的Python程序。
基本上,我的程序运行一个接受 SOAP 请求的 spyne-server。我的程序是多线程的,有时,我用来访问它的客户端会超时。
我已经尝试了几个调试器,例如 PUDB、PDB、WINPDB、PYSTUCK,但我无法从中捕获任何异常,实际上它们也恰好卡住了(CTRL+C 不起作用...)
我取得的最好成绩是使用以下命令从 GDB 获得的:
gdb -ex r --args python myscript.py
GDB 设法捕捉到异常但不显示任何有用的信息:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffd7fff700 (LWP 22573)]
0x000000000057656d in PyEval_EvalCodeEx ()
(gdb) info threads
Id Target Id Frame
* 15 Thread 0x7fffd7fff700 (LWP 22573) "python" 0x000000000057656d in PyEval_EvalCodeEx ()
7 Thread 0x7fffecc2c700 (LWP 22277) "python" 0x00007ffff6998653 in select () at ../sysdeps/unix/syscall-template.S:82
6 Thread 0x7fffed42d700 (LWP 22276) "python" 0x00007ffff6998653 in select () at ../sysdeps/unix/syscall-template.S:82
5 Thread 0x7fffedc2e700 (LWP 22271) "python" sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
4 Thread 0x7fffee42f700 (LWP 22270) "python" sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
3 Thread 0x7fffef9e8700 (LWP 22261) "python" 0x00007ffff6993933 in __GI___poll (fds=<optimized out>, nfds=<optimized out>,
timeout=<optimized out>) at ../sysdeps/unix/sysv/linux/poll.c:87
2 Thread 0x7ffff613f700 (LWP 21988) "python" 0x00007ffff7bcc04d in accept () at ../sysdeps/unix/syscall-template.S:82
1 Thread 0x7ffff7fd6700 (LWP 20970) "python" 0x00007ffff6998653 in select () at ../sysdeps/unix/syscall-template.S:82
(gdb) bt
#0 0x000000000057656d in PyEval_EvalCodeEx ()
#1 0x0000000000577ab0 in function_call.15039 ()
#2 0x00000000004d91b6 in PyObject_Call ()
#3 0x000000000054d8a5 in PyEval_EvalFrameEx ()
#4 0x000000000054c272 in PyEval_EvalFrameEx ()
#5 0x000000000054c272 in PyEval_EvalFrameEx ()
#6 0x000000000054c272 in PyEval_EvalFrameEx ()
#7 0x000000000054c272 in PyEval_EvalFrameEx ()
#8 0x000000000054c272 in PyEval_EvalFrameEx ()
我已经安装了 python2.7-dbg 包来启用命令“py-bt”,但它并没有更多用处:
(gdb) py-bt
#7 (unable to read python frame information)
#8 (unable to read python frame information)
#16 (unable to read python frame information)
#17 (unable to read python frame information)
#18 (unable to read python frame information)
#27 (unable to read python frame information)
#28 (unable to read python frame information)
#32 (unable to read python frame information)
#33 (unable to read python frame information)
#34 (unable to read python frame information)
我在某处读到这是因为 Python 没有调试符号,然后我尝试了以下操作
gdb -ex r --args python-dbg myscript.py
但它也不起作用,我什至无法运行程序,我有几个错误:
ImportError: /usr/lib/python2.7/dist-packages/lxml/etree.so: undefined symbol: Py_InitModule4_64
ImportError: /usr/lib/python2.7/dist-packages/apt_pkg.so: undefined symbol: Py_InitModule4_64
我的选择已经不多了......
关于我的程序的详细信息: 蟒蛇:Python 2.7 操作系统:Ubuntu 12.04 服务器端框架:Spyne(前 SoapLib) 我也在我的程序中使用了 Pyro,这可能是这一切的原因。虽然我已经禁用了 Pyro 上的多线程
【问题讨论】:
标签: python debugging segmentation-fault gdb