You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a simple code which triggers a timeout if a task did not complete
importasyncioasyncdeftask_timeout():
condition=asyncio.Condition()
withawaitcondition:
try:
awaitasyncio.wait_for(condition.wait(), timeout=4)
exceptasyncio.TimeoutErrorase:
print("timeout reached")
# uncomment this line to make the code work# await asyncio.sleep(0)f=asyncio.ensure_future(task_timeout())
loop=asyncio.get_event_loop()
loop.run_until_complete(f)
It throws an exception when leaving the scope for the condition because it expects the lock to be acquired:
RuntimeError: Lock is not acquired.
If you uncomment the line to sleep, it will work because it will continue in the coroutine Condition.wait and call:
yield from self.acquire() => locks.py line 355
I think this is a bug and that this behaviour is not the expected one.
In my previous comment, what I want to implement is not a timeout for a task to complete but more precisely a timeout triggered if the coroutine was not wake up by a notify on the condition.
New changeset e2b340a by Yury Selivanov (Elvis Pranskevichus) in branch 'master': bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216) e2b340a
Activity
christof commentedon May 24, 2018
Hello,
I have a simple code which triggers a timeout if a task did not complete
It throws an exception when leaving the scope for the condition because it expects the lock to be acquired:
RuntimeError: Lock is not acquired.
If you uncomment the line to sleep, it will work because it will continue in the coroutine Condition.wait and call:
yield from self.acquire() => locks.py line 355
I think this is a bug and that this behaviour is not the expected one.
christof commentedon May 24, 2018
In my previous comment, what I want to implement is not a timeout for a task to complete but more precisely a timeout triggered if the coroutine was not wake up by a notify on the condition.
1st1 commentedon May 29, 2018
This is caused by wait_for not waiting for the cancelled task. https://bugs.python.org/issue32751 tracks that bug.
1st1 commentedon May 29, 2018
New changeset e2b340a by Yury Selivanov (Elvis Pranskevichus) in branch 'master':
bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
e2b340a
miss-islington commentedon May 29, 2018
New changeset d8948c5 by Miss Islington (bot) in branch '3.7':
bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
d8948c5