[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5

yury.selivanov python-checkins at python.org
Fri Dec 11 11:34:45 EST 2015


https://hg.python.org/cpython/rev/f8c8441c6cfe
changeset:   99531:f8c8441c6cfe
parent:      99528:64be64bd7444
parent:      99530:e3e7fe5f802a
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Fri Dec 11 11:34:30 2015 -0500
summary:
  Merge 3.5

files:
  Lib/asyncio/tasks.py                |   8 +++++++-
  Lib/test/test_asyncio/test_tasks.py |  15 +++++++++++++++
  2 files changed, 22 insertions(+), 1 deletions(-)


diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -251,7 +251,13 @@
         else:
             if isinstance(result, futures.Future):
                 # Yielded Future must come from Future.__iter__().
-                if result._blocking:
+                if result._loop is not self._loop:
+                    self._loop.call_soon(
+                        self._step,
+                        RuntimeError(
+                            'Task {!r} got Future {!r} attached to a '
+                            'different loop'.format(self, result)))
+                elif result._blocking:
                     result._blocking = False
                     result.add_done_callback(self._wakeup)
                     self._fut_waiter = result
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -76,6 +76,21 @@
     def setUp(self):
         self.loop = self.new_test_loop()
 
+    def test_other_loop_future(self):
+        other_loop = asyncio.new_event_loop()
+        fut = asyncio.Future(loop=other_loop)
+
+        @asyncio.coroutine
+        def run(fut):
+            yield from fut
+
+        try:
+            with self.assertRaisesRegex(RuntimeError,
+                                        r'Task .* got Future .* attached'):
+                self.loop.run_until_complete(run(fut))
+        finally:
+            other_loop.close()
+
     def test_task_class(self):
         @asyncio.coroutine
         def notmuch():

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


More information about the Python-checkins mailing list