Skip to content

Instantly share code, notes, and snippets.

@mpage
Created September 28, 2022 00:37
Show Gist options
  • Save mpage/f2d9ef9e320ae32986e1c8ee87af681d to your computer and use it in GitHub Desktop.
Save mpage/f2d9ef9e320ae32986e1c8ee87af681d to your computer and use it in GitHub Desktop.
import asyncio
from asyncio.tasks import Task
from test.support.cinder import get_await_stack
def dump_await_stack():
async def helper():
print("Stack retrieved using awaiters:")
coro = asyncio.current_task()._coro
stack = get_await_stack(coro)
for coro in reversed(stack):
print(f" {coro.cr_code.co_name}")
return asyncio.create_task(helper())
async def f1():
await f2()
async def f2():
await asyncio.create_task(f3(), name="F3")
async def f3():
tasks = [
asyncio.create_task(f4(), name="F4_0"),
asyncio.create_task(f4(), name="F4_1"),
]
await asyncio.gather(*tasks)
async def f4():
await f5()
async def f5():
await dump_await_stack()
if __name__ == "__main__":
asyncio.run(f1())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment