diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-09 00:58:42 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-09 00:58:42 +0100 |
commit | db86ad7a5b953309a66fd78d022cd08de74fff16 (patch) | |
tree | d18c8b84426eda2317d09a2bced3c9f04fb6d880 | |
parent | e63f6c5bf0da187ce7c4db85c68fb0b8fd23ba4f (diff) | |
download | trollius-db86ad7a5b953309a66fd78d022cd08de74fff16.tar.gz |
Cleanup gather()
Use public methods instead of hacks to consume the exception of a future.
-rw-r--r-- | asyncio/tasks.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/asyncio/tasks.py b/asyncio/tasks.py index 8fc5bea..7959a55 100644 --- a/asyncio/tasks.py +++ b/asyncio/tasks.py @@ -582,11 +582,12 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False): def _done_callback(i, fut): nonlocal nfinished - if outer._state != futures._PENDING: - if fut._exception is not None: + if outer.done(): + if not fut.cancelled(): # Mark exception retrieved. fut.exception() return + if fut._state == futures._CANCELLED: res = futures.CancelledError() if not return_exceptions: @@ -644,9 +645,11 @@ def shield(arg, *, loop=None): def _done_callback(inner): if outer.cancelled(): - # Mark inner's result as retrieved. - inner.cancelled() or inner.exception() + if not inner.cancelled(): + # Mark inner's result as retrieved. + inner.exception() return + if inner.cancelled(): outer.cancel() else: |