Title: `get_all_awaited_by()` shows incorrect call stacks in awaited_by relationships · Issue #135371 · python/cpython · GitHub
Open Graph Title: `get_all_awaited_by()` shows incorrect call stacks in awaited_by relationships · Issue #135371 · python/cpython
X Title: `get_all_awaited_by()` shows incorrect call stacks in awaited_by relationships · Issue #135371 · python/cpython
Description: The current asyncio debugging tools (python -m asyncio ps and python -m asyncio pstree) provide limited visibility into complex async execution patterns, making it extremely difficult to debug production asyncio applications. The fundame...
Open Graph Description: The current asyncio debugging tools (python -m asyncio ps and python -m asyncio pstree) provide limited visibility into complex async execution patterns, making it extremely difficult to debug prod...
X Description: The current asyncio debugging tools (python -m asyncio ps and python -m asyncio pstree) provide limited visibility into complex async execution patterns, making it extremely difficult to debug prod...
Opengraph URL: https://github.com/python/cpython/issues/135371
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`get_all_awaited_by()` shows incorrect call stacks in awaited_by relationships","articleBody":"The current asyncio debugging tools (`python -m asyncio ps` and `python -m asyncio pstree`) provide limited visibility into complex async execution patterns, making it extremely difficult to debug production asyncio applications. \n\nThe fundamental issue is that the current implementation only shows external task dependencies without revealing the internal coroutine call stack. This creates a wrong output because developers cannot see where within a task's execution the code is currently suspended. \n\n## Current vs Correct Output\n\nConsider this example of a complex async application with nested coroutines:\n\n```python\nasync def foo1():\n await foo11()\n\nasync def foo11():\n await foo12()\n\nasync def foo12():\n x = asyncio.create_task(foo2(), name=\"foo2\")\n x2 = asyncio.create_task(foo2(), name=\"foo2\")\n await asyncio.gather(x2, x, return_exceptions=True)\n\nasync def foo2():\n await asyncio.sleep(500)\n\nasync def runner():\n async with taskgroups.TaskGroup() as g:\n g.create_task(foo1(), name=\"foo1.0\")\n g.create_task(foo1(), name=\"foo1.1\") \n g.create_task(foo1(), name=\"foo1.2\")\n g.create_task(foo2(), name=\"foo2\")\n await asyncio.sleep(1000)\n\nasyncio.run(runner())\n```\n\n### Current Implementation\n\nThe existing debugging output makes it nearly impossible to understand what's happening:\n\n**Table output:**\n```\ntid task id task name coroutine chain awaiter name awaiter id \n---------------------------------------------------------------------------------------------------------------------------------------\n2103857 0x7f2a3f87d660 Task-1 0x0 \n2103857 0x7f2a3f154440 foo1.0 sleep -> runner Task-1 0x7f2a3f87d660 \n2103857 0x7f2a3f154630 foo1.1 sleep -> runner Task-1 0x7f2a3f87d660 \n2103857 0x7f2a3fb32be0 foo2 sleep -> runner foo1.0 0x7f2a3f154440 \n```\n\n**Tree output:**\n```\n└── (T) Task-1\n └── /home/user/app.py 27:runner\n └── /home/user/Lib/asyncio/tasks.py 702:sleep\n ├── (T) foo1.0\n │ └── /home/user/app.py 5:foo1\n │ └── /home/user/app.py 8:foo11\n │ └── /home/user/app.py 13:foo12\n │ ├── (T) foo2\n │ └── (T) foo2\n```\n\nThis output is problematic because for the leaf tasks (like the `foo2` tasks), there's no indication of their internal execution state - developers can't tell that these tasks are suspended in `asyncio.sleep()` calls.\n\n### Correct Implementation\n\nThe correct debugging output transforms the debugging experience by providing correct execution context:\n\n**Table output with dual information display:**\n```\ntid task id task name coroutine stack awaiter chain awaiter name awaiter id \n------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n2139407 0x7f70af08fe30 Task-1 sleep -> runner 0x0 \n2139407 0x7f70ae424050 foo1.0 foo12 -> foo11 -> foo1 sleep -> runner Task-1 0x7f70af08fe30 \n2139407 0x7f70ae542890 foo2 sleep -> foo2 foo12 -> foo11 -> foo1 foo1.0 0x7f70ae424050 \n```\n\n**Tree output with complete execution context:**\n```\n└── (T) Task-1\n └── runner /home/user/app.py:27\n └── sleep /home/user/Lib/asyncio/tasks.py:702\n ├── (T) foo1.0\n │ └── foo1 /home/user/app.py:5\n │ └── foo11 /home/user/app.py:8\n │ └── foo12 /home/user/app.py:13\n │ ├── (T) foo2\n │ │ └── foo2 /home/user/app.py:18\n │ │ └── sleep /home/user/Lib/asyncio/tasks.py:702\n │ └── (T) foo2\n │ └── foo2 /home/user/app.py:18\n │ └── sleep /home/user/Lib/asyncio/tasks.py:702\n```\n\nThe correct output immediately reveals crucial information that was previously hidden. Developers can now see that the `foo2` tasks are suspended in `sleep` calls, the `foo1.0` task is suspended in the `foo12` function, and the main `Task-1` is suspended in the `runner` function. This level of detail transforms debugging from guesswork into precise analysis.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-135436\n* gh-135509\n* gh-135534\n* gh-135545\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/pablogsal","@type":"Person","name":"pablogsal"},"datePublished":"2025-06-11T01:34:57Z","url":"https://github.com/python/cpython/issues/135371"}
| 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:a0abc7bb-f089-2a84-82fc-38ed9f45a036 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9AA0:19B6A2:1BAAB0A:2482267:6B022042 |
| html-safe-nonce | 1bec675fbca92b521aa859f73b2d9da6c40d7dc0741d97df6955dfe2d2ddb07b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUEwOjE5QjZBMjoxQkFBQjBBOjI0ODIyNjc6NkIwMjIwNDIiLCJ2aXNpdG9yX2lkIjoiMjQzMjI5ODMyNDM1NTg1MDMwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8743135c19e51870bbacb76c96b92eaaf9018405e381666dabf944851b609a3b |
| hovercard-subject-tag | issue:3135214508 |
| 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/135371/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c1f94ba58e53787c99b701eddf095b249e02df0c6937b5612feb4d3c6ce0a10/python/cpython/issues/135371 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c1f94ba58e53787c99b701eddf095b249e02df0c6937b5612feb4d3c6ce0a10/python/cpython/issues/135371 |
| og:image:alt | The current asyncio debugging tools (python -m asyncio ps and python -m asyncio pstree) provide limited visibility into complex async execution patterns, making it extremely difficult to debug prod... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pablogsal |
| 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