Issue #23485: select.select() is now retried automatically with the recomputed
timeout when interrupted by a signal, except if the signal handler raises an
exception. This change is part of the PEP 475.
The asyncore and selectors module doesn't catch the InterruptedError exception
anymore when calling select.select(), since this function should not raise
InterruptedError anymore.
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 68efd45..5578dda 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -141,10 +141,7 @@
time.sleep(timeout)
return
- try:
- r, w, e = select.select(r, w, e, timeout)
- except InterruptedError:
- return
+ r, w, e = select.select(r, w, e, timeout)
for fd in r:
obj = map.get(fd)
diff --git a/Lib/selectors.py b/Lib/selectors.py
index 6d569c3..4f2a377 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -310,10 +310,7 @@
def select(self, timeout=None):
timeout = None if timeout is None else max(timeout, 0)
ready = []
- try:
- r, w, _ = self._select(self._readers, self._writers, [], timeout)
- except InterruptedError:
- return ready
+ r, w, _ = self._select(self._readers, self._writers, [], timeout)
r = set(r)
w = set(w)
for fd in r | w:
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py
index ba056fb..82cef83 100644
--- a/Lib/test/eintrdata/eintr_tester.py
+++ b/Lib/test/eintrdata/eintr_tester.py
@@ -10,6 +10,7 @@
import io
import os
+import select
import signal
import socket
import time
@@ -303,12 +304,25 @@
self.assertGreaterEqual(dt, self.sleep_time)
+@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()")
+class SelectEINTRTest(EINTRBaseTest):
+ """ EINTR tests for the select module. """
+
+ def test_select(self):
+ t0 = time.monotonic()
+ select.select([], [], [], self.sleep_time)
+ signal.alarm(0)
+ dt = time.monotonic() - t0
+ self.assertGreaterEqual(dt, self.sleep_time)
+
+
def test_main():
support.run_unittest(
OSEINTRTest,
SocketEINTRTest,
TimeEINTRTest,
- SignalEINTRTest)
+ SignalEINTRTest,
+ SelectEINTRTest)
if __name__ == "__main__":