From 606a965f055ae0493bfc36b133e3d58d5ea43d69 Mon Sep 17 00:00:00 2001 From: Dima Tisnek Date: Wed, 28 Aug 2019 20:12:04 +0900 Subject: [PATCH] sensible output for who waits on whom --- test/test_scenario.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/test_scenario.py b/test/test_scenario.py index 100614e..31d7bd3 100644 --- a/test/test_scenario.py +++ b/test/test_scenario.py @@ -34,16 +34,42 @@ async def b_branch(f): await f +def name(t): + try: + # Python3.8 + return t.get_name() + except AttributeError: + return f"Task-{id(t)}" + + async def test(): import sys - # import awaitwhat await asyncio.sleep(0.1) print("### Python native") - for t in asyncio.Task.all_tasks(): + for t in asyncio.all_tasks(): + print(name(t)) asyncio.base_tasks._task_print_stack(t, None, sys.stdout) print() + for t in asyncio.all_tasks(): + waiter = t._fut_waiter + """ + # FIXME waiter is not a Task, it's a: + * _asyncio.Future + * asyncio.tasks._GatheringFuture + * ... + * None + """ + try: + waiter = ", ".join(map(name, waiter._children)) + except AttributeError: + pass + print(f"{name(t)} -> {waiter}") + + # Extended stack + # import awaitwhat + for f in FUTURES: f.set_result(None)