vxgmichel / aiostream

Generator-based operators for asynchronous iteration
http://aiostream.readthedocs.io
GNU General Public License v3.0
800 stars 34 forks source link

Cancel failed tasks #72

Closed cstruct closed 3 years ago

cstruct commented 3 years ago

Cancelling failed tasks makes sure we do not get Task exception was never retrieved if two tasks fail in the same tick.

This fixes vxgmichel/aiostream#71

vxgmichel commented 3 years ago

Thanks a lot for creating this PR @cstruct :)

Would you mind applying the following change instead ?

diff --git a/aiostream/manager.py b/aiostream/manager.py
index bc73de8..e39d70f 100644
--- a/aiostream/manager.py
+++ b/aiostream/manager.py
@@ -48,6 +48,8 @@ class TaskGroup:
         # This makes sense since we don't know in which context the exception
         # was meant to be processed. For instance, a `StopAsyncIteration`
         # might be raised to notify that the end of a streamer has been reached.
+        if not task.cancelled():
+            task.exception()
         self._pending.discard(task)

This way the discarding of the exception follows the corresponding comment. Also, task.exception() raises a CancelledError if the task was cancelled, which is not what we want here.

cstruct commented 3 years ago

Fixed.

Also, task.exception() raises a CancelledError if the task was cancelled, which is not what we want here.

I don't think this was the case since the task wasn't canceled yet, either way this is a lot clearer :+1:

cstruct commented 3 years ago

Updated commit message since the old one did not make sense anymore