-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
(re git tag 0.22.1)
Sometimes ignore_after ignores cancellation, which means if it is used in a task as part of a TaskGroup, the group's join will never finish.
Consider the following example, which I would expect to print taskgroup exited. after <1 second:
import asyncio
from aiorpcx import TaskGroup, TaskTimeout, ignore_after
async def raise_exc():
await asyncio.sleep(0.5)
raise Exception("asd")
async def f():
event = asyncio.Event()
while True:
# poll here; with the option of waking up if event is triggered:
async with ignore_after(0.001): # note: the lower the value, the higher chance race is triggered
async with TaskGroup() as group:
await group.spawn(event.wait())
# (imagine doing some useful work here...)
async def main():
async with TaskGroup() as group:
await group.spawn(f)
await group.spawn(raise_exc)
print(f"taskgroup exited.")
asyncio.run(main())The same example always finishes on aiorpcx 0.18.7.
Note that increasing the timeout constant of ignore_after seems to decrease the chance the issue occurs, try running the example with e.g. 0.05 seconds instead - with that on my machine it prints taskgroup exited. around half the time.
Metadata
Metadata
Assignees
Labels
No labels