Title: TaskGroup suppresses grouped exceptions due to parent task cancellation · Issue #95704 · python/cpython · GitHub
Open Graph Title: TaskGroup suppresses grouped exceptions due to parent task cancellation · Issue #95704 · python/cpython
X Title: TaskGroup suppresses grouped exceptions due to parent task cancellation · Issue #95704 · python/cpython
Description: TaskGroup suppresses grouped exceptions due to parent task cancellation The suggestion was to always check for Cancellation in every finally block in async context managers, however sometimes there's no finally block visible and the prob...
Open Graph Description: TaskGroup suppresses grouped exceptions due to parent task cancellation The suggestion was to always check for Cancellation in every finally block in async context managers, however sometimes there...
X Description: TaskGroup suppresses grouped exceptions due to parent task cancellation The suggestion was to always check for Cancellation in every finally block in async context managers, however sometimes there...
Opengraph URL: https://github.com/python/cpython/issues/95704
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TaskGroup suppresses grouped exceptions due to parent task cancellation ","articleBody":"TaskGroup suppresses grouped exceptions due to parent task cancellation\r\n\r\nThe suggestion was to always check for Cancellation in every finally block in async context managers, however sometimes there's no finally block visible and the problem applies to synchronous context managers too\r\n\r\nIn this demo I'd expect to be able to print: \"handled attribute error\"\r\n\r\n```python\r\nimport asyncio\r\nimport contextlib\r\n\r\nasync def child(sock):\r\n try:\r\n with contextlib.closing(sock):\r\n await asyncio.sleep(2)\r\n except Exception as e:\r\n print(f\"child task got error: {type(e)=} {e=}\")\r\n raise\r\n\r\nclass Sock:\r\n async def aclose(self):\r\n await asyncio.sleep(1)\r\n\r\nasync def main():\r\n try:\r\n sock = Sock()\r\n async with asyncio.timeout(1):\r\n async with asyncio.TaskGroup() as tg:\r\n # Make two concurrent calls to child()\r\n tg.create_task(child(Sock()))\r\n tg.create_task(child(Sock()))\r\n async with contextlib.aclosing(sock):\r\n await asyncio.sleep(2)\r\n except* AttributeError:\r\n print(\"handled attribute error\")\r\n\r\n\r\nasyncio.run(main())\r\n```","author":{"url":"https://github.com/graingert","@type":"Person","name":"graingert"},"datePublished":"2022-08-05T08:31:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/95704/cpython/issues/95704"}
| 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:eaec95cc-388d-10f3-c7b4-494c56b364d8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7D0:3F51C2:552177:6F3EDF:6A5B5975 |
| html-safe-nonce | e44ea88c597222804ccf6f65b833220bec02a67cf7dbe1249d3595eba5057335 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0QwOjNGNTFDMjo1NTIxNzc6NkYzRURGOjZBNUI1OTc1IiwidmlzaXRvcl9pZCI6IjIyMDg4MzUwMzI4MTQ2NzIyNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 63e729422a70ffa0b4c6aeef5a19f88cf5f77bd0f431799891b75577df70f303 |
| hovercard-subject-tag | issue:1329625132 |
| 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/95704/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ca69819a60e0ea1e68221f1f604f60a88bf65d19795e75ffcb072d72363a8a75/python/cpython/issues/95704 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ca69819a60e0ea1e68221f1f604f60a88bf65d19795e75ffcb072d72363a8a75/python/cpython/issues/95704 |
| og:image:alt | TaskGroup suppresses grouped exceptions due to parent task cancellation The suggestion was to always check for Cancellation in every finally block in async context managers, however sometimes there... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | graingert |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width