Title: `python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses · Issue #158522 · python/cpython · GitHub
Open Graph Title: `python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses · Issue #158522 · python/cpython
X Title: `python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses · Issue #158522 · python/cpython
Description: 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.m...
Open Graph Description: 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=...
X Description: 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=...
Opengraph URL: https://github.com/python/cpython/issues/158522
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses","articleBody":"### Bug report\n\n A task whose coroutine recurses is shown with only one frame in the profiler dump\n\nRepro:\n\n```python\nimport asyncio, os, time\n\nasync def rec(n):\n if n:\n await rec(n - 1)\n else:\n print(os.getpid(), flush=True)\n t0 = time.monotonic()\n while time.monotonic() - t0 \u003c 30:\n pass\n\nasync def main():\n await asyncio.create_task(rec(4))\n\nasyncio.run(main())\n```\n\nRun:\n\n```\n./python.exe repro.py\n```\n\n```\nsudo ./python.exe -m profiling.sampling dump --async-aware --async-mode running \u003cpid>\n```\n\n\nActual:\n\n```\nStack dump for PID 68355, thread 4566646 (task 4392209776; most recent call last):\n File \"\u003ctask>\", in Task-1\n File \"repro.py\", line 13, in main\n await asyncio.create_task(rec(4))\n File \"\u003ctask>\", in Task-2\n File \"repro.py\", line 9, in rec\n while time.monotonic() - t0 \u003c 30:\n```\n\nExpected:\n\n```\nStack dump for PID 67670, thread 4562857 (task 4376759664; most recent call last):\n File \"\u003ctask>\", in Task-1\n File \"repro.py\", line 13, in main\n await asyncio.create_task(rec(4))\n File \"\u003ctask>\", in Task-2\n File \"repro.py\", line 5, in rec\n await rec(n - 1)\n File \"repro.py\", line 5, in rec\n await rec(n - 1)\n File \"repro.py\", line 5, in rec\n await rec(n - 1)\n File \"repro.py\", line 5, in rec\n await rec(n - 1)\n File \"repro.py\", line 9, in rec\n while time.monotonic() - t0 \u003c 30:\n```\n\nProposed fix: Stop the frame walk at the task's own frame instead of its code object\n\nI have a fix ready \n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158526\n* gh-158870\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/deadlovelll","@type":"Person","name":"deadlovelll"},"datePublished":"2026-09-30T17:05:24Z","url":"https://github.com/python/cpython/issues/158522"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:27121917-d77e-6ddb-a48c-0b1f44a1475a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1F6:187C1E:1AF04CA:23833BB:6B021B67 |
| html-safe-nonce | 4df09faada853f1e615a107bed405ba559e9a60de2cf9397a51b60b27b14e673 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUY2OjE4N0MxRToxQUYwNENBOjIzODMzQkI6NkIwMjFCNjciLCJ2aXNpdG9yX2lkIjoiNzU2MDA2NDk0MTYwMDkzODg1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6128b3ffbb382706ad92ab07f41ad394615c47ca88c0b29235ccef00e0b25953 |
| hovercard-subject-tag | issue:5650156513 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8787eef3f3a68ce2c9528a913fd729f0f52c5be0d4aafeea10fac64b2ef01fe6/python/cpython/issues/158522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8787eef3f3a68ce2c9528a913fd729f0f52c5be0d4aafeea10fac64b2ef01fe6/python/cpython/issues/158522 |
| og:image:alt | 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=... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | deadlovelll |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width