diff options
| author | jimmylai <albert_chs@yahoo.com.tw> | 2018-05-28 06:42:05 -1000 | 
|---|---|---|
| committer | Yury Selivanov <yury@magic.io> | 2018-05-28 12:42:05 -0400 | 
| commit | e549c4be5fb010f5faf12236af8faa720a1429be (patch) | |
| tree | ca60405804f0eb7f775f3eb82e8e1233093b15c7 /Lib/asyncio/tasks.py | |
| parent | 23f587e395e41bd5e116312b036183f42bc4159b (diff) | |
| download | cpython-git-e549c4be5fb010f5faf12236af8faa720a1429be.tar.gz | |
bpo-33505: Optimize asyncio.ensure_future by reordering if conditions (GH-6836)
Diffstat (limited to 'Lib/asyncio/tasks.py')
| -rw-r--r-- | Lib/asyncio/tasks.py | 10 | 
1 files changed, 5 insertions, 5 deletions
| diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 5df1af6642..4a9db2a3a0 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -542,17 +542,17 @@ def ensure_future(coro_or_future, *, loop=None):      If the argument is a Future, it is returned directly.      """ -    if futures.isfuture(coro_or_future): -        if loop is not None and loop is not futures._get_loop(coro_or_future): -            raise ValueError('loop argument must agree with Future') -        return coro_or_future -    elif coroutines.iscoroutine(coro_or_future): +    if coroutines.iscoroutine(coro_or_future):          if loop is None:              loop = events.get_event_loop()          task = loop.create_task(coro_or_future)          if task._source_traceback:              del task._source_traceback[-1]          return task +    elif futures.isfuture(coro_or_future): +        if loop is not None and loop is not futures._get_loop(coro_or_future): +            raise ValueError('loop argument must agree with Future') +        return coro_or_future      elif inspect.isawaitable(coro_or_future):          return ensure_future(_wrap_awaitable(coro_or_future), loop=loop)      else: | 
