In doc of python 3.7.4, the information about asyncio.gather return_exceptions=False says
"If return_exceptions is False (default), the first raised exception is immediately propagated to the task that awaits on gather(). Other awaitables in the aws sequence won’t be cancelled and will continue to run."
I made a simple code like below:
Is there anything wrong ? or how to understand the doc correctly?
"If return_exceptions is False (default), the first raised exception is immediately propagated to the task that awaits on gather(). Other awaitables in the aws sequence won’t be cancelled and will continue to run."
I made a simple code like below:
import asyncio, time async def fn1(x): await asyncio.sleep(3) print(x) return "fn1" async def fn2(y): await asyncio.sleep(2) raise asyncio.TimeoutError() print(y) return "fn2" async def main(): print("start:",time.ctime()) await asyncio.gather( fn1("fn1"), fn2("fn2"), return_exceptions=False, ) print("end:",time.ctime()) asyncio.run(main())the terminal printed(whole information):
Error:start: Thu Sep 19 17:13:36 2019
Traceback (most recent call last):
File "aio.py", line 25, in <module>
asyncio.run(main())
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "aio.py", line 20, in main
return_exceptions=False,
File "aio.py", line 10, in fn2
raise asyncio.TimeoutError()
concurrent.futures._base.TimeoutError #nothing below
when run this code ,after asyncio.TimeoutError() raised, the other awaitable funtion ("fn1") did't continue working. program quited.this is not worked as the doc says. Is there anything wrong ? or how to understand the doc correctly?