Wednesday, 20 July 2016

Java like thread dumps for the Python process

import threading, sys, 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()))
    print "\n".join(code)

import signal
signal.signal(signal.SIGQUIT, dumpstacks)

3 comments:

  1. Strange "water hack" burns 2 lbs in your sleep

    At least 160k women and men are trying a simple and SECRET "liquids hack" to lose 2 lbs each and every night while they sleep.

    It's scientific and works on anybody.

    This is how you can do it yourself:

    1) Grab a clear glass and fill it with water half glass

    2) And then do this amazing hack

    and you'll be 2 lbs lighter the very next day!

    ReplyDelete