简体   繁体   English

多线程python脚本静默死-如何调试

[英]Multithreaded python script silently dies - how to debug

I have a python script that creates and starts 3 threads, and then goes to a KeyboardInterrupt-catching-loop, to send the threads stop signal when ctrl+c is pressed. 我有一个python脚本,该脚本创建并启动3个线程,然后转到KeyboardInterrupt-catching-loop,在按ctrl + c时发送线程停止信号。

The threads' run method has a top level try-except which logs every exception, also the top level code that creates threads is wrapped into try-except to log every exception. 线程的run方法具有记录所有异常的顶级try-except,还将创建线程的顶层代码包装到try-except中以记录每个异常。

But the script just dies randomly, sometimes after a day, sometimes after an hour, without any exception being logged. 但是脚本只是随机终止,有时是一天之后,有时是一个小时之后,并且没有任何异常被记录下来。

It's driving me crazy, because I have no further ideas how to debug this. 这让我发疯,因为我没有进一步的想法来调试它。

Any ideas guys? 有想法吗?

Edit: As Luper suggested a look into syslog indeed revealed 编辑:正如卢珀建议对系统日志的调查确实揭示了

python[27737]: segfault at 0 ip 0808e1d3 sp b662c5e0 error 4 in python2.5[8048000+fb000]

Still no idea how to go from here. 仍然不知道如何从这里出发。

As for the code, it doesnt do anything fancy, some file parsing and copying between directories, and calling some executables via os.system 至于代码,它没有做任何花哨的事情,在目录之间进行一些文件解析和复制,并通过os.system调用一些可执行文件。

A segfault in python is usually caused by a bug in a module written in C. There is nothing the interpreter can do. python中的段错误通常是由用C编写的模块中的错误引起的。解释器无法执行任何操作。

A quick search revealed that the common problems that cause a segfault are 1) bad memory (but you should see more segfaults - run memcheck from a live CD if you suspect this), 2) corrupted installation (try reinstall python and packages, re-downloading everything) and 3) bugs (duh). 快速搜索发现,导致段错误的常见问题是:1)内存不足(但您应该看到更多段错误-如果怀疑此问题,请从实时CD运行memcheck); 2)安装损坏(尝试重新安装python和软件包,然后重新安装)下载所有内容)和3)错误(duh)。

Try if it is 1) or 2) first, then to see where the process stops, can use strace to record all system calls. 首先尝试是1)还是2),然后查看进程在哪里停止,可以使用strace记录所有系统调用。 That may give you some other clue of what is going on (the output file may grow big): 这可能会为您提供其他线索(输出文件可能会变大):

strace -f python my_script.py > strace.out 2>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM