[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Guido van Rossum
Guido van Rossum added the comment: We should really stop appending to a closed issue. Anyway, raising ExceptionGroup is backwards incompatible, since "except CancelledError" wouldn't cancel the group. -- ___ Python tracker

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Thomas Grainger
Thomas Grainger added the comment: there could be multiple messages here perhaps it could be: ``` finally: # Must reacquire lock even if wait is cancelled cancelled = [] while True: try: await self.acquire()

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Also Future.result() and Future.exception() can raise a CancelledError. So a CancelledError raised in a task may not contain a message passed to Task.cancel(). import asyncio import random async def main(): fut = asyncio.Future() fut.cancel()

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Andrew Svetlov
Andrew Svetlov added the comment: Serhiy is right, Condition.wait() has the following code: finally: # Must reacquire lock even if wait is cancelled cancelled = False while True: try: await self.acquire()

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Chris Jerdonek
Chris Jerdonek added the comment: For future reference, with Andrew's change merged above, the traceback for the example snippet in my message above: https://bugs.python.org/issue45390#msg403570 is now the following. Observe that (1) the call to sleep() continues to be present, but (2)

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Seems a CancelledError message can be lost also in Condition.wait(). -- nosy: +serhiy.storchaka ___ Python tracker ___

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-22 Thread Andrew Svetlov
Change by Andrew Svetlov : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: New changeset 4140bcb1cd76dec5cf8d398f4d0e86c438c987d0 by Andrew Svetlov in branch 'main': bpo-45390: Propagate CancelledError's message from cancelled task to its awaiter (GH-31383)

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-18 Thread Guido van Rossum
Change by Guido van Rossum : -- nosy: +gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-17 Thread Chris Jerdonek
Chris Jerdonek added the comment: Andrew, the approach I described would I feel be much better. It would result in more concise, less verbose tracebacks, as opposed to more verbose -- not just because the message won't be repeated, but also because it eliminates the unneeded creation of

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-17 Thread Marco Pagliaricci
Marco Pagliaricci added the comment: Andrew, many thanks for your time, solving this issue. I think your solution is the best to fix this little problem and I agree with you on backporting. My Best Regards, and thanks again. Marco On Thu, Feb 17, 2022 at 10:29 AM Andrew Svetlov wrote: > >

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-17 Thread Andrew Svetlov
Andrew Svetlov added the comment: I have a pull request for the issue. It doesn't use `Future.set_exception()` but creates a new CancelledError() with propagated message. The result is the same, except raised exceptions are not comparable by `is` check. As a benefit, `_cancelled_exc` works

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-17 Thread Andrew Svetlov
Change by Andrew Svetlov : -- keywords: +patch pull_requests: +29531 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31383 ___ Python tracker ___

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-17 Thread Andrew Svetlov
Change by Andrew Svetlov : -- versions: +Python 3.11 -Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Chris Jerdonek
Chris Jerdonek added the comment: Here's a simplification of Marco's snippet to focus the discussion. import asyncio async def job(): # raise RuntimeError('error!') await asyncio.sleep(5) async def main(): task = asyncio.create_task(job()) await asyncio.sleep(1)

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Marco Pagliaricci
Marco Pagliaricci added the comment: Chris, ok, I have modified the snippet of code to better show what I mean. Still here, the message of the CancelledError exception is lost, but if I comment line 10, and uncomment line 11, so I throw a ValueError("TEST"), that "TEST" string will be printed,

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Chris Jerdonek
Chris Jerdonek added the comment: I still don't see you calling asyncio.Task.exception() in your new attachment... -- ___ Python tracker ___

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Marco Pagliaricci
Marco Pagliaricci added the comment: Chris, I'm attaching to this e-mail the code I'm referring to. As you can see, in line 10, I re-raise the asyncio.CancelledError exception with a message "TEST". That message is lost, due to the reasons we've talked about. My point is that, if we substitute

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Chris Jerdonek
Chris Jerdonek added the comment: > 2) Now: if I re-raise the asyncio.CancelledError as-is, I lose the message, if I call the `asyncio.Task.exception()` function. Re-raise asyncio.CancelledError where? (And what do you mean by "re-raise"?) Call asyncio.Task.exception() where? This isn't part

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-09 Thread Marco Pagliaricci
Marco Pagliaricci added the comment: OK, I see your point. But I still can't understand one thing and I think it's very confusing: 1) if you see my example, inside the job() coroutine, I get correctly cancelled with an `asyncio.CancelledError` exception containing my message. 2) Now: if I

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-07 Thread Thomas Grainger
Thomas Grainger added the comment: afaik this is intentional https://bugs.python.org/issue31033 -- nosy: +graingert ___ Python tracker ___

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-07 Thread Chris Jerdonek
Chris Jerdonek added the comment: > But, once the asyncio.Task is cancelled, is impossible to retrieve that > original asyncio.CancelledError(msg) exception with the message, because it > seems that *a new* asyncio.CancelledError() [without the message] is raised > when

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-06 Thread Ben
Ben added the comment: This seems to be present in both the Python implementation as well as the accelerated C _asyncio module. It looks like that when a Task awaits a cancelled future, the task itself is cancelled but the cancellation message is not propagated to the task.

[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-06 Thread Marco Pagliaricci
New submission from Marco Pagliaricci : I've spotted a little bug in how asyncio.CancelledError() exception is propagated inside an asyncio.Task. Since python 3.9 the asyncio.Task.cancel() method has a new 'msg' parameter, that will create an asyncio.CancelledError(msg) exception