How to force python's VM to print a stack trace?
I'm dealing with a python-written server that locks开发者_如何学JAVA 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.
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)
You can find a (Unix-only) solution in this question.
精彩评论