Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ def _step(self, exc=None):
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
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ class TaskTests(test_utils.TestCase):
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():
Expand Down