Skip to content

Instantly share code, notes, and snippets.

@akaptur
Last active August 29, 2015 14:07
Show Gist options
  • Save akaptur/b81d0189215f5d247d87 to your computer and use it in GitHub Desktop.
Save akaptur/b81d0189215f5d247d87 to your computer and use it in GitHub Desktop.
def countdown(n, times_called=[0],):
print(times_called[0], " ", n, " ")
# print "frame: %s" % id(inspect.currentframe())
times_called[0] += 1
if n == 1:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
n_frames = len(inspect.getouterframes(inspect.currentframe()))
print("\nexception at %s, n of %s, stack height of %s" % (times_called[0], n, n_frames))
# print [frame_printer(frame_tup[0]) for frame_tup in inspect.getouterframes(inspect.currentframe())][-20:]
return countdown(n-1)
# Contrast with:
def countdown(n, times_called=[0],):
print(times_called[0], " ", n, " ")
# print "frame: %s" % id(inspect.currentframe())
times_called[0] += 1
if n == 1:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
# n_frames = len(inspect.getouterframes(inspect.currentframe()))
print("\nexception at %s, n of %s, stack height of %s" % (times_called[0], n, n))
# print [frame_printer(frame_tup[0]) for frame_tup in inspect.getouterframes(inspect.currentframe())][-20:]
return countdown(n-1)
# Frame jumping works differently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment