classification
Title: PEP 475: handle EINTR in the time module, retry sleep()
Type: Stage:
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: haypo, neologix, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2015-03-12 15:37 by haypo, last changed 2015-03-20 02:06 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
sleep_eintr.patch haypo, 2015-03-12 15:37 review
sleep.py haypo, 2015-03-12 15:38
sleep_eintr-2.patch haypo, 2015-03-12 15:45 review
Messages (11)
msg237948 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-12 15:37
Attached patch changes time.sleep() to retry select() when select() is interrupted by a signal or retry WaitForSingleObjectEx() when the signal SIGINT is received on Windows.

The patch drops support for EMX, sorry! I didn't know EMX, I had to Google it: "EMX is a free 32-bit DOS extender which adds some properties of Unix to MS-compatible DOS and IBM's OS/2 operating systems." (OS/2 support was dropped in Python 3.4  by the PEP 11.)

The patch also drops support for Watcom C compiler. I guess that it's also something specific to MS-DOS or very old (and unsupported) Windows versions.

select.select() is available on all platforms according to the doc, so I don't understand why we would not use it on all platforms for time.sleep() in 2015!
https://docs.python.org/dev/library/select.html#select.select
msg237949 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-12 15:38
The patch includes a unit test for POSIX.

For Windows, you can test manually using the attached sleep.py program: press CTRL+c to send SIGINT signals.
msg237952 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-12 15:45
Oh, test_signal fails with the patch because time.sleep() is not interrupted by a signal. New patch.

I also reverted #ifdef order in floatsleep() to have a patch easier to review.
msg237953 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-12 15:46
Note: test_signal will have to be modified again when select will also retry on EINTR :-) See issue #23485. For example, test_signal.test_wakeup_fd_early() can register a signal handler which raises an exception and catch InterruptedError.
msg237959 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2015-03-12 16:35
As for the change to select/poll/etc, IIRC Guido was opposed to it,
that's why I didn't update them.
msg237983 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-12 20:27
Le jeudi 12 mars 2015, Charles-François Natali <report@bugs.python.org> a
écrit :
>
> As for the change to select/poll/etc, IIRC Guido was opposed to it,
> that's why I didn't update them.
>

Wait what? can you elaborate? I'm not aware of that.
msg238269 - (view) Author: Roundup Robot (python-dev) Date: 2015-03-17 09:50
New changeset 4accc35cbfcf by Victor Stinner in branch 'default':
Revert changeset d927047b1d8eb87738676980a24930d053ba2150
https://hg.python.org/cpython/rev/4accc35cbfcf
msg238270 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2015-03-17 09:52
I commited sleep_eintr.patch by mistake. After this change, test_socket started to fail on Windows. I don't understand why.

http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/5836/steps/test/logs/stdio

======================================================================
ERROR: testClose (test.test_socket.TCPCloserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_socket.py", line 3723, in testClose
    read, write, err = select.select([sd], [], [], 1.0)
TypeError: argument must be an int, or have a fileno() method.

======================================================================
FAIL: testRecv (test.test_socket.NonBlockingTCPTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_socket.py", line 3883, in testRecv
    self.fail("Error trying to do non-blocking recv.")
AssertionError: Error trying to do non-blocking recv.
msg238557 - (view) Author: Roundup Robot (python-dev) Date: 2015-03-19 20:59
New changeset b1abd06465fc by Victor Stinner in branch 'default':
Issue #23646: If time.sleep() is interrupted by a signal, the sleep is now
https://hg.python.org/cpython/rev/b1abd06465fc
msg238594 - (view) Author: Roundup Robot (python-dev) Date: 2015-03-20 01:01
New changeset 9882cc2efd36 by Victor Stinner in branch 'default':
Issue #23646: Enhance precision of time.sleep() and socket timeout when
https://hg.python.org/cpython/rev/9882cc2efd36
msg238599 - (view) Author: Roundup Robot (python-dev) Date: 2015-03-20 02:06
New changeset 1291649f38df by Victor Stinner in branch 'default':
Issue #23646: Fix test_threading on Windows
https://hg.python.org/cpython/rev/1291649f38df
History
Date User Action Args
2015-03-20 02:06:25python-devsetmessages: + msg238599
2015-03-20 01:01:59python-devsetmessages: + msg238594
2015-03-19 23:00:18hayposetstatus: open -> closed
resolution: fixed
2015-03-19 20:59:59python-devsetmessages: + msg238557
2015-03-17 09:52:08hayposetmessages: + msg238270
2015-03-17 09:50:12python-devsetnosy: + python-dev
messages: + msg238269
2015-03-12 20:27:58hayposetmessages: + msg237983
2015-03-12 16:35:18neologixsetmessages: + msg237959
2015-03-12 15:51:50haypolinkissue23648 dependencies
2015-03-12 15:46:36hayposetmessages: + msg237953
2015-03-12 15:45:09hayposetfiles: + sleep_eintr-2.patch

messages: + msg237952
2015-03-12 15:38:31hayposetfiles: + sleep.py

messages: + msg237949
2015-03-12 15:37:42haypocreate