Sep-20-2019, 08:49 AM
(This post was last modified: Sep-20-2019, 08:49 AM by learnpython.)
Thanks for your helping!
I have ran your code.
Firstly, if set
Secondly, if set
terminal's output information is as below:
if there is an Exception in one of the awaitable tasks or coroutines, the others awatiable tasks will still run. In the examples you gave,
the print sentence will be running and give a printing on terminal. but nothing happended in the termial.
I have ran your code.
Firstly, if set
asyncio.gather(*aws, loop = None, return_exceptions = True)then we can get the Exception as an object in the result list. that's a good choice to know which awaitable task or coroutine had an exception after asyncio running.
Secondly, if set
asyncio.gather(*aws, loop = None, return_exceptions = False)after the asyncio.TimeoutError() raised, "fn1 is called with First call" and "fn1 is called with Third call" both sentences didn't print yet.
terminal's output information is as below:
Output:#nothing above
start: Thu Sep 19 21:24:37 2019
return_exceptions=False
raise_error is called with y=Second call
Catched Exception from gather
We don't get the result back, but the tasks are not canceled
As expected you get a NameError, result1 does not exist
# nothing below
what makes me confused is on my understanding about the doc Quote:"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."
https://docs.python.org/3/library/asynci...ncurrently
if there is an Exception in one of the awaitable tasks or coroutines, the others awatiable tasks will still run. In the examples you gave,
async def fn1(x): await asyncio.sleep(3) print(f"fn1 is called with x={x}") # from the doc says, I think this sentence will still run return f"Hello from fn1: {x}"
the print sentence will be running and give a printing on terminal. but nothing happended in the termial.