diff -r 8f72bf88f471 Lib/asyncio/futures.py --- a/Lib/asyncio/futures.py Sat Feb 20 12:59:36 2016 -0800 +++ b/Lib/asyncio/futures.py Mon Feb 22 03:14:39 2016 +1100 @@ -341,6 +341,8 @@ raise InvalidStateError('{}: {!r}'.format(self._state, self)) if isinstance(exception, type): exception = exception() + if isinstance(exception, StopIteration): + raise TypeError("StopException interacts badly with generators and cannot be raised into a Future") self._exception = exception self._state = _FINISHED self._schedule_callbacks() diff -r 8f72bf88f471 Lib/test/test_asyncio/test_futures.py --- a/Lib/test/test_asyncio/test_futures.py Sat Feb 20 12:59:36 2016 -0800 +++ b/Lib/test/test_asyncio/test_futures.py Mon Feb 22 03:14:39 2016 +1100 @@ -76,6 +76,9 @@ f = asyncio.Future(loop=self.loop) self.assertRaises(asyncio.InvalidStateError, f.exception) + # StopIteration cannot be raised into a Future - issue26221 + self.assertRaises(TypeError, f.set_exception, StopIteration) + f.set_exception(exc) self.assertFalse(f.cancelled()) self.assertTrue(f.done())