Title: `asyncio.shield()` incorrectly records its caller as awaiting the shielded task in the call graph · Issue #162395 · python/cpython · GitHub
Open Graph Title: `asyncio.shield()` incorrectly records its caller as awaiting the shielded task in the call graph · Issue #162395 · python/cpython
X Title: `asyncio.shield()` incorrectly records its caller as awaiting the shielded task in the call graph · Issue #162395 · python/cpython
Description: Bug report If another task awaits the future returned by shield(), the call graph still shows the task that called shield() Same kind of bug as #162061 Repro: import asyncio async def consume(fut): await fut async def main(): release = a...
Open Graph Description: Bug report If another task awaits the future returned by shield(), the call graph still shows the task that called shield() Same kind of bug as #162061 Repro: import asyncio async def consume(fut):...
X Description: Bug report If another task awaits the future returned by shield(), the call graph still shows the task that called shield() Same kind of bug as #162061 Repro: import asyncio async def consume(fut):...
Opengraph URL: https://github.com/python/cpython/issues/162395
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`asyncio.shield()` incorrectly records its caller as awaiting the shielded task in the call graph","articleBody":"### Bug report\n\nIf another task awaits the future returned by shield(), the call graph still shows the task that called shield()\n\nSame kind of bug as https://github.com/python/cpython/issues/162061\n\nRepro:\n\n```python\nimport asyncio\n\nasync def consume(fut):\n await fut\n\nasync def main():\n release = asyncio.Event()\n child = asyncio.create_task(release.wait(), name=\"child\")\n shielded = asyncio.shield(child)\n consumer = asyncio.create_task(consume(shielded), name=\"consumer\", eager_start=True)\n\n asyncio.print_call_graph(child, limit=0)\n\n release.set()\n await consumer\n\nasyncio.run(main())\n```\n\nActual:\n\n```\n* Task(name='child', id=0x1015b49b0)\n + Awaited by:\n * Task(name='Task-1', id=0x1015b47d0)\n```\n\nProblem here is the same - `main` doesnt actually awaits `child` at the moment of graph capture\n\nExpected:\n\n```\n* Task(name='child', id=0x1033789b0)\n + Awaited by:\n * Future(id=0x103012c30)\n + Awaited by:\n * Task(name='consumer', id=0x1033683f0)\n```\n\nProposed fix - link the shielded task to the future returned by shield() instead of the task that called it\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-162396\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/deadlovelll","@type":"Person","name":"deadlovelll"},"datePublished":"2026-11-21T17:43:49Z","url":"https://github.com/python/cpython/issues/162395"}
| 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:fd7b69e0-3a0c-ec05-e7dd-51da60f031b3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCD0:ADA9D:381DF54:47F692D:6B01E963 |
| html-safe-nonce | 5af5912fd7f7b9408be231fa6270a91bf5fc3bb22de9f53a2c10929bb3211184 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0QwOkFEQTlEOjM4MURGNTQ6NDdGNjkyRDo2QjAxRTk2MyIsInZpc2l0b3JfaWQiOiI0OTE3MTExNDk5ODA3Mzg1OTU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7998820b0d83a2ae2964dcd4ce6b9aa9d48a5462a78f9810fb305c126c124ab6 |
| hovercard-subject-tag | issue:6532270932 |
| 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/162395/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8193726b2e896166f4605e20299266eba167ff526db227e074f0d39225754a6/python/cpython/issues/162395 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8193726b2e896166f4605e20299266eba167ff526db227e074f0d39225754a6/python/cpython/issues/162395 |
| og:image:alt | Bug report If another task awaits the future returned by shield(), the call graph still shows the task that called shield() Same kind of bug as #162061 Repro: import asyncio async def consume(fut):... |
| 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