I'm dealing with a python-written server that locks up, and stops working, including logging. I wonder if there's a python equivalent to java's "kill -3" signal that at least prints the current stacktrace.
Asked
Active
Viewed 4,593 times
3 Answers
7
Use the faulthandler module. https://pypi.python.org/pypi/faulthandler/
import faulthandler
faulthandler.register(signal.SIGUSR1)
This works outside of Python's interpreter loop's signal handling at the C level so it will work even when the Python interpreter itself is hung waiting on something else.
gps
- 1,234
- 11
- 11
-
As you hint, `faulthandler` is included in the standard library from Python 3.3+ – rescdsk Apr 16 '15 at 18:57
2
import signal, traceback
def quit_handler(signum,frame):
traceback.print_stack()
signal.signal(signal.SIGQUIT,quit_handler)
John La Rooy
- 281,034
- 50
- 354
- 495
-
If the server "locks up", it doesn't necessarily get a SIGQUIT signal, I guess. – AndiDog Jan 29 '10 at 21:35
-
@AndiDog: I think you're supposed to use `kill(1)` to send it one when you manually detect that it has locked up. – SamB Nov 21 '10 at 18:24