diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 19:38:00 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-30 19:38:00 (GMT) |
commit | 3c7d6e069331ceab0da6b794e4069f07bb3d4aac (patch) | |
tree | 42284993b3b0cdc127c69218140a2650e73b8e60 /Lib | |
parent | fa09beb1508f782b51ba0a2815c07e0294f40e95 (diff) | |
download | cpython-3c7d6e069331ceab0da6b794e4069f07bb3d4aac.zip cpython-3c7d6e069331ceab0da6b794e4069f07bb3d4aac.tar.gz cpython-3c7d6e069331ceab0da6b794e4069f07bb3d4aac.tar.bz2 |
Issue #23485: select.poll.poll() is now retried when interrupted by a signal
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncore.py | 6 | ||||
-rw-r--r-- | Lib/selectors.py | 7 | ||||
-rw-r--r-- | Lib/test/eintrdata/eintr_tester.py | 20 |
3 files changed, 22 insertions, 11 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 5578dda..3b51f0f 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -179,10 +179,8 @@ def poll2(timeout=0.0, map=None): flags |= select.POLLOUT if flags: pollster.register(fd, flags) - try: - r = pollster.poll(timeout) - except InterruptedError: - r = [] + + r = pollster.poll(timeout) for fd, flags in r: obj = map.get(fd) if obj is None: diff --git a/Lib/selectors.py b/Lib/selectors.py index 4f2a377..bf48ebf 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -359,11 +359,10 @@ if hasattr(select, 'poll'): # poll() has a resolution of 1 millisecond, round away from # zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) + + fd_event_list = self._poll.poll(timeout) + ready = [] - try: - fd_event_list = self._poll.poll(timeout) - except InterruptedError: - return ready for fd, event in fd_event_list: events = 0 if event & ~select.POLLIN: diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py index 82cef83..3da964d 100644 --- a/Lib/test/eintrdata/eintr_tester.py +++ b/Lib/test/eintrdata/eintr_tester.py @@ -38,8 +38,12 @@ class EINTRBaseTest(unittest.TestCase): cls.signal_period) @classmethod - def tearDownClass(cls): + def stop_alarm(cls): signal.setitimer(signal.ITIMER_REAL, 0, 0) + + @classmethod + def tearDownClass(cls): + cls.stop_alarm() signal.signal(signal.SIGALRM, cls.orig_handler) @classmethod @@ -260,7 +264,7 @@ class TimeEINTRTest(EINTRBaseTest): def test_sleep(self): t0 = time.monotonic() time.sleep(self.sleep_time) - signal.alarm(0) + self.stop_alarm() dt = time.monotonic() - t0 self.assertGreaterEqual(dt, self.sleep_time) @@ -311,7 +315,17 @@ class SelectEINTRTest(EINTRBaseTest): def test_select(self): t0 = time.monotonic() select.select([], [], [], self.sleep_time) - signal.alarm(0) + self.stop_alarm() + dt = time.monotonic() - t0 + self.assertGreaterEqual(dt, self.sleep_time) + + @unittest.skipUnless(hasattr(select, 'poll'), 'need select.poll') + def test_poll(self): + poller = select.poll() + + t0 = time.monotonic() + poller.poll(self.sleep_time * 1e3) + self.stop_alarm() dt = time.monotonic() - t0 self.assertGreaterEqual(dt, self.sleep_time) |