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.
Method 1: By using print_exc() method. This method prints exception information and stack trace entries from traceback object tb to file.
We can obtain a stack trace from a thread by calling the getStackTrace() method on the Thread instance. It returns an array of StackTraceElement, from which details about stack frames of the thread can be found.
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.
See also: http://docs.python.org/dev/library/faulthandler
import signal, traceback
def quit_handler(signum,frame):
traceback.print_stack()
signal.signal(signal.SIGQUIT,quit_handler)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With