diff options
author | Yury Selivanov <yury@magic.io> | 2019-05-27 12:45:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 12:45:12 (GMT) |
commit | 431b540bf79f0982559b1b0e420b1b085f667bb7 (patch) | |
tree | 2e7027339ce786cc90e04cba1b03c71ecf38dfda /Lib/asyncio/unix_events.py | |
parent | 16cefb0bc7b05c08caf08525398ff178c35dece4 (diff) | |
download | cpython-431b540bf79f0982559b1b0e420b1b085f667bb7.zip cpython-431b540bf79f0982559b1b0e420b1b085f667bb7.tar.gz cpython-431b540bf79f0982559b1b0e420b1b085f667bb7.tar.bz2 |
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make:
an "except Exception" clause breaking Tasks cancellation.
In addition to this change, we stop inheriting asyncio.TimeoutError
and asyncio.InvalidStateError from their concurrent.futures.*
counterparts. There's no point for these exceptions to share the
inheritance chain.
In 3.9 we'll focus on implementing supervisors and cancel scopes,
which should allow better handling of all exceptions, including
SystemExit and KeyboardInterrupt
Diffstat (limited to 'Lib/asyncio/unix_events.py')
-rw-r--r-- | Lib/asyncio/unix_events.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 1aa3b39..81d10b1 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -194,7 +194,9 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): self._child_watcher_callback, transp) try: await waiter - except Exception: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException: transp.close() await transp._wait() raise @@ -390,7 +392,9 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): else: self._sock_sendfile_update_filepos(fileno, offset, total_sent) fut.set_exception(exc) - except Exception as exc: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException as exc: self._sock_sendfile_update_filepos(fileno, offset, total_sent) fut.set_exception(exc) else: @@ -641,7 +645,9 @@ class _UnixWritePipeTransport(transports._FlowControlMixin, n = os.write(self._fileno, data) except (BlockingIOError, InterruptedError): n = 0 - except Exception as exc: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException as exc: self._conn_lost += 1 self._fatal_error(exc, 'Fatal write error on pipe transport') return @@ -661,7 +667,9 @@ class _UnixWritePipeTransport(transports._FlowControlMixin, n = os.write(self._fileno, self._buffer) except (BlockingIOError, InterruptedError): pass - except Exception as exc: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException as exc: self._buffer.clear() self._conn_lost += 1 # Remove writer here, _fatal_error() doesn't it @@ -879,7 +887,9 @@ class BaseChildWatcher(AbstractChildWatcher): def _sig_chld(self): try: self._do_waitpid_all() - except Exception as exc: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException as exc: # self._loop should always be available here # as '_sig_chld' is added as a signal handler # in 'attach_loop' |