Skip to content

Commit

Permalink
Introduce a signal handler for printing thread stack traces
Browse files Browse the repository at this point in the history
as a debugging aid, introduce a signal handler for printing stack traces

kill -USR1 <pid>

will result in a stack dump
  • Loading branch information
vondele authored and ppigazzini committed May 16, 2024
1 parent 01d6dbc commit 697bbcf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/fishtest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import base64
import hashlib
import signal
import sys
import threading
import traceback
from pathlib import Path

from fishtest.rundb import RunDb
Expand All @@ -14,8 +18,22 @@
from fishtest import helpers


def thread_stack_dump(sig, frame):
for th in threading.enumerate():
print("=================== ", th, " ======================", flush=True)
try:
traceback.print_stack(sys._current_frames()[th.ident])
except Exception:
print("Failed to print traceback, the thread is probably gone", flush=True)


def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""

# Register handler, will list the stack traces of all active threads
# trigger with: kill -USR1 <pid>
signal.signal(signal.SIGUSR1, thread_stack_dump)

session_factory = SignedCookieSessionFactory("fishtest")
config = Configurator(
settings=settings,
Expand Down

0 comments on commit 697bbcf

Please sign in to comment.