From e17368cf26e70cdd917d6b26ee5baa71a373eb63 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Fri, 15 May 2015 00:05:12 +0200 Subject: [PATCH] Catch SIGUSR1: log threads stack traces --- nemubot/__main__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nemubot/__main__.py b/nemubot/__main__.py index 8e9320e..114b83c 100644 --- a/nemubot/__main__.py +++ b/nemubot/__main__.py @@ -152,6 +152,15 @@ def main(): context.sync_queue.put_nowait(["loadconf", path]) signal.signal(signal.SIGHUP, sighuphandler) + def sigusr1handler(signum, frame): + """On SIGHUSR1, display stacktraces""" + import traceback + for threadId, stack in sys._current_frames().items(): + logger.debug("########### Thread %d:\n%s", + threadId, + "".join(traceback.format_stack(stack))) + signal.signal(signal.SIGUSR1, sigusr1handler) + # Here we go! context.start()