Skip to content

Instantly share code, notes, and snippets.

@njsmith
Created February 17, 2017 14:09
Show Gist options
  • Select an option

  • Save njsmith/d566941ee3566f2c69f45c5bab65eb51 to your computer and use it in GitHub Desktop.

Select an option

Save njsmith/d566941ee3566f2c69f45c5bab65eb51 to your computer and use it in GitHub Desktop.
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