Merge 3.5

This commit is contained in:
Yury Selivanov 2015-12-11 11:34:30 -05:00
commit 8bb6fa85e1
2 changed files with 22 additions and 1 deletions

View File

@ -251,7 +251,13 @@ class Task(futures.Future):
else: else:
if isinstance(result, futures.Future): if isinstance(result, futures.Future):
# Yielded Future must come from Future.__iter__(). # 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._blocking = False
result.add_done_callback(self._wakeup) result.add_done_callback(self._wakeup)
self._fut_waiter = result self._fut_waiter = result

View File

@ -76,6 +76,21 @@ class TaskTests(test_utils.TestCase):
def setUp(self): def setUp(self):
self.loop = self.new_test_loop() 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): def test_task_class(self):
@asyncio.coroutine @asyncio.coroutine
def notmuch(): def notmuch():