Multi-threaded python script dies silently - how to debug
I have a python script that creates and starts 3 threads and then goes into the KeyboardInterrupt-catching-loop to send a thread stop signal when ctrl + c is pressed.
The method for starting threads uses a top-level try-except that logs each exception, and the top-level code that creates threads is wrapped in try-except to log each exception.
But the script just dies randomly, sometimes every other day, sometimes an hour later, without any exceptions being logged.
This is driving me crazy because I have no further ideas on how to debug this.
Any ideas guys?
Edit: As Luper suggested that a look at syslog actually showed
python[27737]: segfault at 0 ip 0808e1d3 sp b662c5e0 error 4 in python2.5[8048000+fb000]
I have no idea how to get out of here.
As far as the code goes, it doesn't do anything fancy, some parsing and copying files between directories and calling some executables through os.system
a source to share
Segfault in python is usually caused by a bug in a module written in C. There is nothing the interpreter can do.
A quick search showed that the common issues causing segfault are 1) bad memory (but you should see more segfaults - run memcheck from a live CD if you suspect it), 2) corrupted installation (try reinstalling python and packages, re-download everything ) and 3) errors (duh).
Try if it is 1) or 2) first and then to see where the process stopped, you can use strace
to record all system calls. This might give you another clue as to what's going on (the output file might grow larger):
strace -f python my_script.py > strace.out 2>&1
a source to share