Closes #22429, asyncio: Fix EventLoop.run_until_complete(), don't stop the

event loop if a BaseException is raised, because the event loop is already
stopped.
This commit is contained in:
Victor Stinner 2014-12-05 01:44:10 +01:00
parent 4c85ec99f3
commit f3e2e09213
2 changed files with 37 additions and 2 deletions

View file

@ -638,6 +638,31 @@ class BaseEventLoopTests(test_utils.TestCase):
self.assertFalse(self.loop.call_exception_handler.called)
def test_run_until_complete_baseexception(self):
# Python issue #22429: run_until_complete() must not schedule a pending
# call to stop() if the future raised a BaseException
@asyncio.coroutine
def raise_keyboard_interrupt():
raise KeyboardInterrupt
self.loop._process_events = mock.Mock()
try:
self.loop.run_until_complete(raise_keyboard_interrupt())
except KeyboardInterrupt:
pass
def func():
self.loop.stop()
func.called = True
func.called = False
try:
self.loop.call_soon(func)
self.loop.run_forever()
except KeyboardInterrupt:
pass
self.assertTrue(func.called)
class MyProto(asyncio.Protocol):
done = None