[Python-Dev] RFC: PEP 475, Retry system calls failing with EINTR

Victor Stinner victor.stinner at gmail.com
Tue Sep 2 23:35:28 CEST 2014

2014-09-02 23:02 GMT+02:00 Matthew Woodcraft <matthew at woodcraft.me.uk>:
> I think people who use sleep() in their programs could benefit from not
> having to worry about EINTR as much as anyone else.

The behaviour of time.sleep() is worse than what I expected. On UNIX,
if select() fails with EINTR, time.sleep() calls PyErr_CheckSignals().
If the signal handler doesn't raise an exception, time.sleep() returns
None and just simply ignores the error.

But on Windows, it's the opposite. If time.sleep() is interrupt by
CTRL+c, time.sleep() raises an InterruptedError...

Good luck to write portable code :-p

With the PEP 475, time.sleep(secs) now has a well defined behaviour.
It sleeps at least "secs" seconds, retry the syscall on EINTR, and
raises an exception if the signal handler raises an exception.


More information about the Python-Dev mailing list