Skip to content

Instantly share code, notes, and snippets.

@evanlong
Created January 3, 2012 04:10
Show Gist options
  • Save evanlong/1553435 to your computer and use it in GitHub Desktop.
Save evanlong/1553435 to your computer and use it in GitHub Desktop.
dump stack info along with locals
import sys
def foo(n):
a = "Hello"
b = "bob"
c = 1 / n
return a + " " + b
def bar():
a = foo(1)
b = foo(0)
print a
print b
def baz():
bar()
#basic global handler to dump exception with locals information
try:
baz()
except BaseException,e:
tbo = sys.exc_info()[2]
while tbo != None:
print tbo.tb_frame.f_code
print " ", tbo.tb_frame.f_locals
print
tbo = tbo.tb_next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment