This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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: pitrou, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2011-07-01 10:25 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sleep_signal.patch vstinner, 2011-07-01 10:25 review
sleep_signal-2.patch vstinner, 2011-07-01 11:13 review
Messages (5)
msg139562 - (view) Author: STINNER Victor (vstinner) * (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 (vstinner) * (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) (Python triager) 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
2022-04-11 14:57:19adminsetgithub: 56671
2011-07-01 12:20:34vstinnersetstatus: 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:33vstinnersetfiles: + sleep_signal-2.patch

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