diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-07 03:06:16 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-02-07 03:06:16 (GMT) |
commit | 622be340fdf4110c77e1f86bd13a01fc30c2bb65 (patch) | |
tree | e38a7edec44d792e95dbc7e8ac3d28a9767d965b /Lib/asyncio/tasks.py | |
parent | 2ddb39a6959d9ce4044ea501e58428d5b34e0312 (diff) | |
download | cpython-622be340fdf4110c77e1f86bd13a01fc30c2bb65.zip cpython-622be340fdf4110c77e1f86bd13a01fc30c2bb65.tar.gz cpython-622be340fdf4110c77e1f86bd13a01fc30c2bb65.tar.bz2 |
asyncio.tasks: Fix as_completed, gather & wait to work with duplicate coroutines
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r-- | Lib/asyncio/tasks.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index a5708b4..5ad0652 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -364,7 +364,7 @@ def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED): if loop is None: loop = events.get_event_loop() - fs = set(async(f, loop=loop) for f in fs) + fs = {async(f, loop=loop) for f in set(fs)} if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED): raise ValueError('Invalid return_when value: {}'.format(return_when)) @@ -476,7 +476,7 @@ def as_completed(fs, *, loop=None, timeout=None): """ loop = loop if loop is not None else events.get_event_loop() deadline = None if timeout is None else loop.time() + timeout - todo = set(async(f, loop=loop) for f in fs) + todo = {async(f, loop=loop) for f in set(fs)} completed = collections.deque() @coroutine @@ -568,7 +568,8 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False): prevent the cancellation of one child to cause other children to be cancelled.) """ - children = [async(fut, loop=loop) for fut in coros_or_futures] + arg_to_fut = {arg: async(arg, loop=loop) for arg in set(coros_or_futures)} + children = [arg_to_fut[arg] for arg in coros_or_futures] n = len(children) if n == 0: outer = futures.Future(loop=loop) |