From f5d20993f8c5b1100dead9679f8dd2e4dc086427 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sat, 10 Jun 2017 20:13:58 +0200 Subject: [PATCH] #30624 / selectors: use bare except clause in order to not leave the fd in a bad state in case of error --- Lib/selectors.py | 4 ++-- Misc/NEWS | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/selectors.py b/Lib/selectors.py index edde22c634b059d..f8b17a14f944d44 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -387,7 +387,7 @@ def modify(self, fileobj, events, data=None): selector_events |= self._EVENT_WRITE try: self._selector.modify(key.fd, selector_events) - except Exception: + except: super().unregister(fileobj) raise changed = True @@ -524,7 +524,7 @@ def register(self, fileobj, events, data=None): kev = select.kevent(key.fd, select.KQ_FILTER_WRITE, select.KQ_EV_ADD) self._selector.control([kev], 0, 0) - except Exception: + except: super().unregister(fileobj) raise return key diff --git a/Misc/NEWS b/Misc/NEWS index 185ec0ed866b201..3eb5d890a874b37 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -350,6 +350,10 @@ Extension Modules Library ------- +- bpo-30624: selectors does not take KeyboardInterrupt and SystemExit into + account, leaving a fd in a bad state in case of error. Patch by Giampaolo + Rodola'. + - bpo-30595: multiprocessing.Queue.get() with a timeout now polls its reader in non-blocking mode if it succeeded to aquire the lock but the acquire took longer than the timeout.