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 committed May 12, 2024
1 parent b204b37 commit a6aa33e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion server/fishtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@
from pyramid.httpexceptions import HTTPFound
from pyramid.security import forget
from pyramid.session import SignedCookieSessionFactory

from fishtest import helpers
import traceback, signal, sys, threading


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 as e:
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 a6aa33e

Please sign in to comment.