From 431b540bf79f0982559b1b0e420b1b085f667bb7 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 27 May 2019 14:45:12 +0200 Subject: 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 --- Lib/asyncio/events.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/asyncio/events.py') diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 9a923514db..d381b1c596 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -79,7 +79,9 @@ class Handle: def _run(self): try: self._context.run(self._callback, *self._args) - except Exception as exc: + except (SystemExit, KeyboardInterrupt): + raise + except BaseException as exc: cb = format_helpers._format_callback_source( self._callback, self._args) msg = f'Exception in callback {cb}' -- cgit v1.2.1