A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/asyncio/issues/288 below:

Script freezes on await coroutine cancelled by wait_for if this coroutine contains any await inside it's CancelledError handling · Issue #288 · python/asyncio · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4