Title: `asyncio.TaskGroup` swallows cancellations coming from outside of it · Issue #155433 · python/cpython · GitHub
Open Graph Title: `asyncio.TaskGroup` swallows cancellations coming from outside of it · Issue #155433 · python/cpython
X Title: `asyncio.TaskGroup` swallows cancellations coming from outside of it · Issue #155433 · python/cpython
Description: Bug report Bug description: After tg.cancel() taskgroup silently swallows any cancellation requested from outside it Repro: import asyncio async def worker(): try: await asyncio.sleep(3600) finally: await asyncio.sleep(1) async def main(...
Open Graph Description: Bug report Bug description: After tg.cancel() taskgroup silently swallows any cancellation requested from outside it Repro: import asyncio async def worker(): try: await asyncio.sleep(3600) finally...
X Description: Bug report Bug description: After tg.cancel() taskgroup silently swallows any cancellation requested from outside it Repro: import asyncio async def worker(): try: await asyncio.sleep(3600) finally...
Opengraph URL: https://github.com/python/cpython/issues/155433
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`asyncio.TaskGroup` swallows cancellations coming from outside of it","articleBody":"# Bug report\n\n### Bug description:\n\nAfter `tg.cancel()` taskgroup silently swallows any cancellation requested from outside it\n\nRepro:\n\n```python\nimport asyncio\n\nasync def worker():\n try:\n await asyncio.sleep(3600)\n finally:\n await asyncio.sleep(1)\n\nasync def main():\n async with asyncio.timeout(0.5):\n async with asyncio.TaskGroup() as tg:\n tg.create_task(worker())\n await asyncio.sleep(0.1)\n tg.cancel()\n print(\"no error\")\n\nasyncio.run(main())\n```\n\nExpected output:\n\n```\nraise TimeoutError from exc_val\nTimeoutError\n```\n\nBut actually:\n\n```\nno error\n```\n\nProposed fix - add else branch: if `uncancel()` leaves requests pending, cancellation was not ours, so we need to propogate it \n\n```python\n if self._parent_cancel_requested:\n # If this flag is set we *must* call uncancel().\n if self._parent_task.uncancel() == 0:\n # If there are no pending cancellations left,\n # don't propagate CancelledError.\n propagate_cancellation_error = None\n else:\n propagate_cancellation_error = exceptions.CancelledError()\n```\n\nHave 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-155439\n* gh-157329\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/deadlovelll","@type":"Person","name":"deadlovelll"},"datePublished":"2026-08-09T13:05:09Z","url":"https://github.com/python/cpython/issues/155433"}
| 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:daace90e-901b-ba4e-eadc-07d34e26144a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBC6:11EACE:3534BEC:4703F3F:6B02027A |
| html-safe-nonce | 0daa1de96b5c295ccd449a7b1b355c7f246e0ee72bbe6f34df877de6dc8e34a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkM2OjExRUFDRTozNTM0QkVDOjQ3MDNGM0Y6NkIwMjAyN0EiLCJ2aXNpdG9yX2lkIjoiODQyMzkxNzYzMjMxMDM0NjM2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d2bd70d212b61ffd720b692e5aa3de988d4e19b4c178768479db9aad3b516c11 |
| hovercard-subject-tag | issue:5102674368 |
| 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/155433/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7cd94375d885b4e181cdfec9fd5f10ad892f710afc3a77cc709185136756dbff/python/cpython/issues/155433 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7cd94375d885b4e181cdfec9fd5f10ad892f710afc3a77cc709185136756dbff/python/cpython/issues/155433 |
| og:image:alt | Bug report Bug description: After tg.cancel() taskgroup silently swallows any cancellation requested from outside it Repro: import asyncio async def worker(): try: await asyncio.sleep(3600) finally... |
| 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