Script freezes on await coroutine cancelled by wait_for if this coroutine contains any await inside it's CancelledError handling
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Description
import asyncio async def some_func(): try: await asyncio.sleep(2) except asyncio.CancelledError: # await asyncio.sleep(1) print('cancelled') async def main(): coro = some_func() try: await asyncio.wait_for(coro, timeout=1) except asyncio.TimeoutError: await coro print('timeout') if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(main())
Output as expected:
But if you uncomment line inside some_func script will freeze (without printing). It can be avoided if we will use task instead of coroutine. But behavior with coroutine seems to be unclear: why everything works if line is commented and just freezes (without any error) if line is uncommented? If coroutine can't be awaited in this case shouldn't we get exception if we try to awaite it?
Windows 10, Python 3.5.0