[Python-checkins] cpython (3.4): asyncio: Error if awaiting in parallel on the same coroutine

yury.selivanov python-checkins at python.org
Wed Nov 18 12:40:46 EST 2015


https://hg.python.org/cpython/rev/89d66f912671
changeset:   99201:89d66f912671
branch:      3.4
parent:      99197:660bdfaada64
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Wed Nov 18 12:39:45 2015 -0500
summary:
  asyncio: Error if awaiting in parallel on the same coroutine

This change won't do anything in CPython 3.4

See https://github.com/python/asyncio/pull/293 for details.

files:
  Lib/asyncio/coroutines.py |  8 +++++++-
  1 files changed, 7 insertions(+), 1 deletions(-)


diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -140,7 +140,13 @@
 
     if compat.PY35:
 
-        __await__ = __iter__ # make compatible with 'await' expression
+        def __await__(self):
+            cr_await = getattr(self.gen, 'cr_await', None)
+            if cr_await is not None:
+                raise RuntimeError(
+                    "Cannot await on coroutine {!r} while it's "
+                    "awaiting for {!r}".format(self.gen, cr_await))
+            return self
 
         @property
         def gi_yieldfrom(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list