开发者

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

开发者 https://www.devze.com 2022-12-18 07:40 出处:网络
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 pri

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消