Skip to content

Instantly share code, notes, and snippets.

@njsmith
Last active February 17, 2017 10:22
Show Gist options
  • Select an option

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

Select an option

Save njsmith/1c3742362bb6f5cc505f69cb66db2e71 to your computer and use it in GitHub Desktop.
import sys
import trio
def dump_stack(where):
print("-- {} --".format(where))
frame = sys._getframe(1)
while frame:
print(frame.f_code.co_name)
frame = frame.f_back
async def f():
dump_stack("f before yielding")
await g()
dump_stack("f after yielding")
async def g():
dump_stack("g before yielding")
await h()
dump_stack("g after yielding")
async def h():
dump_stack("h before yielding")
await trio.sleep(0)
dump_stack("h after yielding")
trio.run(f)
~/trio$ python check-stack.py
-- f before yielding --
f
send
run_impl
run
<module>
-- g before yielding --
g
f
send
run_impl
run
<module>
-- h before yielding --
h
g
f
send
run_impl
run
<module>
-- h after yielding --
h
send
run_impl
run
<module>
-- g after yielding --
g
send
run_impl
run
<module>
-- f after yielding --
f
send
run_impl
run
<module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment