]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
asyncio: Error if awaiting in parallel on the same coroutine
authorYury Selivanov <yselivanov@sprymix.com>
Wed, 18 Nov 2015 17:39:45 +0000 (12:39 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Wed, 18 Nov 2015 17:39:45 +0000 (12:39 -0500)
This change won't do anything in CPython 3.4

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

Lib/asyncio/coroutines.py

index e11b21b09754b40e0aa91da9aee3fd296599670f..3a92c7d7552219a08c74e35939f20f5de85c6264 100644 (file)
@@ -140,7 +140,13 @@ class CoroWrapper:
 
     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):