diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-19 20:54:09 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-19 20:54:09 (GMT) |
commit | 79d68f929d8def878766965f513b628023f809b5 (patch) | |
tree | 943c927ae839eb2b115f88d997cd29094ddd23ab /Lib/test/eintrdata | |
parent | 0ed56a0b421e02da3ed3626a5b9e0ad076f68ce0 (diff) | |
download | cpython-79d68f929d8def878766965f513b628023f809b5.zip cpython-79d68f929d8def878766965f513b628023f809b5.tar.gz cpython-79d68f929d8def878766965f513b628023f809b5.tar.bz2 |
Issue #23646: If time.sleep() is interrupted by a signal, the sleep is now
retried with the recomputed delay, except if the signal handler raises an
exception (PEP 475).
Modify also test_signal to use a monotonic clock instead of the system clock.
Diffstat (limited to 'Lib/test/eintrdata')
-rw-r--r-- | Lib/test/eintrdata/eintr_tester.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py index 40dca84..400dd21 100644 --- a/Lib/test/eintrdata/eintr_tester.py +++ b/Lib/test/eintrdata/eintr_tester.py @@ -252,8 +252,26 @@ class SocketEINTRTest(EINTRBaseTest): lambda path: os.close(os.open(path, os.O_WRONLY))) +@unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()") +class TimeEINTRTest(EINTRBaseTest): + """ EINTR tests for the time module. """ + + def test_sleep(self): + t0 = time.monotonic() + # time.sleep() may retry when interrupted by a signal + time.sleep(2) + signal.alarm(0) + dt = time.monotonic() - t0 + # Tolerate a difference 100 ms: on Windows, time.monotonic() has + # a resolution of 15.6 ms or greater + self.assertGreaterEqual(dt, 1.9) + + def test_main(): - support.run_unittest(OSEINTRTest, SocketEINTRTest) + support.run_unittest( + OSEINTRTest, + SocketEINTRTest, + TimeEINTRTest) if __name__ == "__main__": |