Last active
August 29, 2015 14:07
-
-
Save akaptur/b81d0189215f5d247d87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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