Created
October 6, 2012 06:47
-
-
Save fcicq/3844246 to your computer and use it in GitHub Desktop.
Things you didn't know about Python https://speakerdeck.com/u/mitsuhiko/p/didntknow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import traceback | |
def dump_threads(): | |
for thread_id, frame in sys._current_frames().iteritems(): | |
print 'Thread #%d' % thread_id | |
print ''.join(traceback.format_stack(frame)) | |
# Usage: print_frame_info(sys._getframe()) | |
def print_frame_info(frame): | |
print 'module: %s' % frame.f_globals.get('__name__') | |
print 'filename: %s' % frame.f_code.co_filename | |
print 'current line: %d' % frame.f_lineno | |
loc = dict((k, v) for k, v in frame.f_locals.iteritems() if not k.startswith('__')) | |
print 'local variables: %s' % loc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would prefer for the latter: