classification
Title: time.sleep(1): call PyErr_CheckSignals() if the sleep was interrupted
Type: Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: haypo, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2011-07-01 10:25 by haypo, last changed 2011-07-01 12:20 by haypo. This issue is now closed.

Files
File name Uploaded Description Edit
sleep_signal.patch haypo, 2011-07-01 10:25 review
sleep_signal-2.patch haypo, 2011-07-01 11:13 review
Messages (5)
msg139562 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2011-07-01 10:25
While reading floatsleep() (time.sleep) code for issue #12459, I noticed that the Python signal handler is not called in floatsleep() if a signal interrupted the sleep. Well, it just "works" because the bytecode evaluation loop will call PyErr_CheckSignals() before executing the next instruction (the C signal handler signals calls Py_AddPendingCall whichs signals that the pending call to the eval loop using "eval_breaker"), but it would be better to call it directly.

Attached calls explicitly and immediatly PyErr_CheckSignals() in the sleep and Windows implementations of floatsleep().

It's not really a bug, so I prefer to not touch Python 2.7 and 3.2, only Python 3.3.
msg139564 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-07-01 10:28
You don't *need* to call PyErr_CheckSignals() explicitly, PyErr_SetFromErrno() does it for you.
msg139567 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2011-07-01 11:13
The sleep implementation of floatsleep() doesn't call PyErr_SetFromErrno() if errno is EINTR, whereas EINTR indicates that select() was interrupted. I agree that PyErr_CheckSignals() is overkill in the Windows implementation.

My new patch is more explicit: only add a special case for the select implementation, if errno is EINTR.
msg139568 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-07-01 11:47
> My new patch is more explicit: only add a special case for the select
> implementation, if errno is EINTR.

Looks good to me!
msg139570 - (view) Author: Roundup Robot (python-dev) Date: 2011-07-01 12:19
New changeset 583be15e22ca by Victor Stinner in branch 'default':
Issue #12462: time.sleep() now calls immediatly the (Python) signal handler if
http://hg.python.org/cpython/rev/583be15e22ca
History
Date User Action Args
2011-07-01 12:20:34hayposetstatus: open -> closed
resolution: fixed
2011-07-01 12:19:31python-devsetnosy: + python-dev
messages: + msg139570
2011-07-01 11:47:36pitrousetmessages: + msg139568
2011-07-01 11:13:33hayposetfiles: + sleep_signal-2.patch

messages: + msg139567
2011-07-01 10:28:03pitrousetmessages: + msg139564
2011-07-01 10:25:05haypocreate