Re: Behavior of `asyncio.gather` when one of submitted tasks raises a `KeyboardInterrupt`.

"Yves Duprat" <[email protected]>
Newsgroups gmane.comp.python.devel
Message-ID <[email protected]>
Sure, I will do. Work is in progress !!

Guido van Rossum wrote:
> I'm sorry, I don't know the answer. Maybe you can read some of the source
> code and report back here if you find any clues?
> On Thu, Jun 9, 2022 at 1:53 PM Yves Duprat [email protected] wrote:
> > Sorry for my imprecision, can you read the changes about the results:
> > With one coroutine in `asyncio.gather([sub_task()])`, result is:
> >         main_task(), be: CancelledError()
> > __main__ <class 'KeyboardInterrupt'>
> > With two coroutines `asyncio.gather([sub_task(), asyncio.sleep(0)])` ,
> > result is:
> >         main_task(), be: KeyboardInterrupt()
> > __main__ <class 'KeyboardInterrupt'>
> > --
> > Yves Duprat wrote:
> > Thank you for the straightforward explanation. May I ask you another
> > question?
> > I don't understand the behavior of this waiting primitive. So here is
> > the case below:
> > import asyncio
> > e = KeyboardInterrupt  # or SystemExit
> > async def sub_task():
> >     raise e
> > async def main_task():
> >     try:
> >         await asyncio.gather(
> >             # -- aws --
> >             sub_task(),
> >             asyncio.sleep(0)
> >         )
> >     except Exception as e:
> >         print('\tmain_task(), e:', repr(e))
> >         raise
> >     except BaseException as e:
> >         print('\tmain_task(), be:', repr(e))
> > if __name__ == '__main__':
> >     try:
> >         asyncio.run(main_task())
> >     except e:
> >         print(f'__main__ {e}')
> > 
> > When one coroutine `[sub_task()]`, result is:
> >         main_task(), be: CancelledError()
> > __main__ <class 'KeyboardInterrupt'>
> > When two coroutines `[sub_task(), sleep(0)]` , result is:
> >         main_task(), be: KeyboardInterrupt()
> > __main__ <class 'KeyboardInterrupt'>
> > Why are results so different when `aws` contains single coroutine or two
> > coroutines ?
> > Thank for your time
> > Yves
> > Guido van Rossum wrote:
> > KeyboardInterrupt is generally not handled properly by asyncio, the
> > normal
> > behavior here is that the code just exits with a traceback.
> > On Tue, Jun 7, 2022 at 11:00 AM Yves Duprat [email protected] wrote:
> > Hi,
> > regarding this [issue93122](
> > https://github.com/python/cpython/issues/93122),
> > I am wondering what is the normal behavior of `asyncio.gather` when
> > one of
> > the submitted tasks raises a `KeyboardInterrupt` exception ? --
> > regardless
> > of the value of the `return_exception` parameter.
> > It seems that this primitive does not behave the same way with
> > `KeyboardInterrupt` and `ZeroDivisionError` exceptions. But may be it
> > is
> > normal ?
> > I have searched in the documentation [here](
> > https://docs.python.org/3/library/asyncio-task.html#asyncio.gather)
> > but I
> > did not find anything.
> > Thanks for your help.
> > Yves
> > _______________________________________________
> > Python-Dev mailing list -- [email protected]
> > To unsubscribe send an email to [email protected]
> > https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
> > https://mail.python.org/archives/list/[email protected]/message/5KVY7SSD.
> > ..
> > Code of Conduct: http://python.org/psf/codeofconduct/
> > --Guido van Rossum (python.org/~guido)
> > *Pronouns: he/him **(why is my pronoun here?)*
> > http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c.
> > ..
> > 
> > Python-Dev mailing list -- [email protected]
> > To unsubscribe send an email to [email protected]
> > https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
> > https://mail.python.org/archives/list/[email protected]/message/CIDCWFDX...
> > Code of Conduct: http://python.org/psf/codeofconduct/
> > -- 
> --Guido van Rossum (python.org/~guido)
> *Pronouns: he/him **(why is my pronoun here?)*
> http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.