Author christof
Recipients asvetlov, christof, yselivanov
Date 2018-05-24.19:10:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1527189023.9.0.682650639539.issue33638@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,

I have a simple code which triggers a timeout if a task did not complete

import asyncio

async def task_timeout():
    condition = asyncio.Condition()
    with await condition:
        try:
            await asyncio.wait_for(condition.wait(), timeout=4)
        except asyncio.TimeoutError as e:
 
            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.
History
Date User Action Args
2018-05-24 19:10:23christofsetrecipients: + christof, asvetlov, yselivanov
2018-05-24 19:10:23christofsetmessageid: <1527189023.9.0.682650639539.issue33638@psf.upfronthosting.co.za>
2018-05-24 19:10:23christoflinkissue33638 messages
2018-05-24 19:10:23christofcreate