2 TracebackPrinter.py - Prints the current stack trace to a specified
3 file when SIGUSR1 is received.
6 Based-On: python-traceback-signal
7 <https://github.com/angelcam/python-traceback-signal>
16 def print_traceback(wfd, frame):
17 msg = "Traceback signal received.\nTraceback (most recent call last):\n"
18 msg += ''.join(traceback.format_stack(frame))
21 def register_sigusr(wfd):
22 def sigusr_handler(_, frame):
23 # first param is which signal
24 print_traceback(wfd, frame)
26 signal.signal(signal.SIGUSR1, sigusr_handler)
28 def traceback_init(f):
29 wfd = os.open(f, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o600)