How to force python's VM to print a stack trace?

debugging, python

Solution

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

Problem

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.

Original source

Related problems