mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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:
parent
4c85ec99f3
commit
f3e2e09213
2 changed files with 37 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue