diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-11 22:27:25 -0400 |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-11 22:27:25 -0400 |
commit | a1f57455e4307635cecfb71b5dac27e7a7ffde8c (patch) | |
tree | be92702399d28394c662f34cd09ae0bc36668cc4 /Lib/asyncio/tasks.py | |
parent | c81235c1b12ace9530f143fc07097a3133c8f4d6 (diff) | |
download | cpython-a1f57455e4307635cecfb71b5dac27e7a7ffde8c.tar.gz |
asyncio: Support PEP 492. Issue #24017.
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r-- | Lib/asyncio/tasks.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index f617b62be2..fcb383389c 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -11,6 +11,7 @@ import functools import inspect import linecache import sys +import types import traceback import warnings import weakref @@ -73,7 +74,10 @@ class Task(futures.Future): super().__init__(loop=loop) if self._source_traceback: del self._source_traceback[-1] - self._coro = iter(coro) # Use the iterator just in case. + if coro.__class__ is types.GeneratorType: + self._coro = coro + else: + self._coro = iter(coro) # Use the iterator just in case. self._fut_waiter = None self._must_cancel = False self._loop.call_soon(self._step) @@ -236,7 +240,7 @@ class Task(futures.Future): elif value is not None: result = coro.send(value) else: - result = next(coro) + result = coro.send(None) except StopIteration as exc: self.set_result(exc.value) except futures.CancelledError as exc: |