Skip to content

Instantly share code, notes, and snippets.

@midnightmagic
Created October 21, 2015 10:26
Show Gist options
  • Save midnightmagic/820e530ab960871b7cf0 to your computer and use it in GitHub Desktop.
Save midnightmagic/820e530ab960871b7cf0 to your computer and use it in GitHub Desktop.
Adds SIGUSR1 framedump to messages.log for Limnoria supybot, applies to: 685bedcd74daa06bf9d785ca575b47257f7d3322
*** supybot 2015-10-03 04:25:29.211350138 -0700
--- /opt-limnoria-old/bin/supybot 2015-10-10 03:59:25.091350138 -0700
***************
*** 1,4 ****
! #!/usr/bin/env python
###
# Copyright (c) 2003-2004, Jeremiah Fincher
--- 1,4 ----
! #!/usr/bin/python
###
# Copyright (c) 2003-2004, Jeremiah Fincher
***************
*** 58,63 ****
--- 58,78 ----
signal.signal(signal.SIGTERM, _termHandler)
+ import threading, traceback
+
+ def _dumpstacks(signal, frame):
+ id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
+ code = []
+ for threadId, stack in sys._current_frames().items():
+ code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId))
+ for filename, lineno, name, line in traceback.extract_stack(stack):
+ code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
+ if line:
+ code.append(" %s" % (line.strip()))
+ log.info("\n".join(code))
+
+ signal.signal(signal.SIGUSR1, _dumpstacks)
+
import time
import optparse
import textwrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment