diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-12-05 01:44:10 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-12-05 01:44:10 +0100 |
commit | f3e2e09213ecac36c3c3634a06cb7badf3e4217e (patch) | |
tree | 47720db212aeb42092da2ce37290d16161173bcc /Lib/asyncio/base_events.py | |
parent | 4c85ec99f39bb6687f6fb0d23c6a7daedcde990e (diff) | |
download | cpython-git-f3e2e09213ecac36c3c3634a06cb7badf3e4217e.tar.gz |
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.
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r-- | Lib/asyncio/base_events.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 7c38b093e0..0c7316ea97 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -102,6 +102,16 @@ def _raise_stop_error(*args): raise _StopError +def _run_until_complete_cb(fut): + exc = fut._exception + if (isinstance(exc, BaseException) + and not isinstance(exc, Exception)): + # Issue #22429: run_forever() already finished, no need to + # stop it. + return + _raise_stop_error() + + class Server(events.AbstractServer): def __init__(self, loop, sockets): @@ -268,7 +278,7 @@ class BaseEventLoop(events.AbstractEventLoop): # is no need to log the "destroy pending task" message future._log_destroy_pending = False - future.add_done_callback(_raise_stop_error) + future.add_done_callback(_run_until_complete_cb) try: self.run_forever() except: @@ -278,7 +288,7 @@ class BaseEventLoop(events.AbstractEventLoop): # local task. future.exception() raise - future.remove_done_callback(_raise_stop_error) + future.remove_done_callback(_run_until_complete_cb) if not future.done(): raise RuntimeError('Event loop stopped before Future completed.') |