It seems yappi gets confused when a coroutine is scheduled as a task and awaited from the same function and the task returns first. If the task returns first the timings from the explicit await on the coroutine get lost (still contributes to the call count):
from asyncio import create_task, run, sleep
import yappi
yappi.set_clock_type('wall')
async def test(d=0):
t = create_task(sleep(5+d))
await sleep(5)
await t
for d in [-2, 0, 2]:
with yappi.run():
run(test(d))
print(f'#### d={d} (expect tsub ~ ttot ~ 2*5+d={2*5+d}):') # but we get 5-d if d < 0
yappi.get_func_stats(filter_callback=lambda x: yappi.func_matches(x, [sleep])).print_all()
yappi.clear_stats()
It has been a while since this task is opened. It turns out to be a simpler fix than I originally thought. Will be fixed in https://github.com/sumerc/yappi/pull/94
It seems
yappi
gets confused when a coroutine is scheduled as a task and awaited from the same function and the task returns first. If the task returns first the timings from the explicit await on the coroutine get lost (still contributes to the call count):