Bug report
A task whose coroutine recurses is shown with only one frame in the profiler dump
Repro:
import asyncio, os, time
async def rec(n):
if n:
await rec(n - 1)
else:
print(os.getpid(), flush=True)
t0 = time.monotonic()
while time.monotonic() - t0 < 30:
pass
async def main():
await asyncio.create_task(rec(4))
asyncio.run(main())
Run:
sudo ./python.exe -m profiling.sampling dump --async-aware --async-mode running <pid>
Actual:
Stack dump for PID 68355, thread 4566646 (task 4392209776; most recent call last):
File "<task>", in Task-1
File "repro.py", line 13, in main
await asyncio.create_task(rec(4))
File "<task>", in Task-2
File "repro.py", line 9, in rec
while time.monotonic() - t0 < 30:
Expected:
Stack dump for PID 67670, thread 4562857 (task 4376759664; most recent call last):
File "<task>", in Task-1
File "repro.py", line 13, in main
await asyncio.create_task(rec(4))
File "<task>", in Task-2
File "repro.py", line 5, in rec
await rec(n - 1)
File "repro.py", line 5, in rec
await rec(n - 1)
File "repro.py", line 5, in rec
await rec(n - 1)
File "repro.py", line 5, in rec
await rec(n - 1)
File "repro.py", line 9, in rec
while time.monotonic() - t0 < 30:
Proposed fix: Stop the frame walk at the task's own frame instead of its code object
I have a fix ready
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
A task whose coroutine recurses is shown with only one frame in the profiler dump
Repro:
Run:
Actual:
Expected:
Proposed fix: Stop the frame walk at the task's own frame instead of its code object
I have a fix ready
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs