GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — GH-95289: Always call uncancel() when required by gvanrossum · Pull Request #95513 · python/cpython Conversation
|
|
Hi, import asyncio class MyException(Exception): pass async def async_fn2(): try: await asyncio.sleep(0.0) raise MyException finally: print("raise done") async def main(): task = asyncio.current_task() try: async with asyncio.TaskGroup() as tg: tg.create_task(async_fn2()) await asyncio.sleep(1) except* (MyException, asyncio.CancelledError) as e: # How to check a private `_parent_cancel_requested` attr here, outside the class ? print(f"{e.exceptions} -> {task.cancelling()=}, {tg._parent_cancel_requested=}") async def supermain(): t = asyncio.create_task(main()) await asyncio.sleep(0) t.cancel() print("cancel main task") await asyncio.sleep(1) print(f"{t.cancelling()=} must be 1, confirm ?") asyncio.run(supermain()) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
That code looks racy with the sleep(0.0) calls, but it is correct that since your supermain code cancels main, uncancel will not be called. Note that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I wonder whether it is important to check if parent task is not |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
What problem would that solve? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dde8683 to
839f7f3
Compare
839f7f3 to
6cd25fc
Compare
Problem is already solved with the 'externally cancel' case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Superseded by #95602 which includes tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.