Created
February 17, 2017 14:09
-
-
Save njsmith/d566941ee3566f2c69f45c5bab65eb51 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
| import sys | |
| def dump_stack(where): | |
| print("-- {} --".format(where)) | |
| frame = sys._getframe(1) | |
| while frame: | |
| print(frame.f_code.co_name) | |
| frame = frame.f_back | |
| def f(): | |
| dump_stack("f before yielding") | |
| yield from g() | |
| dump_stack("f after yielding") | |
| def g(): | |
| dump_stack("g before yielding") | |
| yield from h() | |
| dump_stack("g after yielding") | |
| def h(): | |
| dump_stack("h before yielding") | |
| try: | |
| yield | |
| except Exception: | |
| pass | |
| dump_stack("h after yielding") | |
| gen = f() | |
| gen.send(None) | |
| try: | |
| # Replace this with gen.send(None) and you get sensible stacks | |
| gen.throw(RuntimeError) | |
| except StopIteration: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment