New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time.sleep(1): call PyErr_CheckSignals() if the sleep was interrupted #56671
Comments
While reading floatsleep() (time.sleep) code for issue bpo-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. |
You don't *need* to call PyErr_CheckSignals() explicitly, PyErr_SetFromErrno() does it for you. |
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. |
Looks good to me! |
New changeset 583be15e22ca by Victor Stinner in branch 'default': |
`IOError` is an alias of `OSError` since Python 3.3. Python 3 also indroduced a new exception `InterruptedError` which represents `EINTR`. The `time.sleep()` call could raise IOError: [Errno 4] Interrupted function call on KBInt under Python 2, which would be `InterruptedError` under Python 3 but it's not raised anymore post PEP 475 that was implemented in Python 3.5. So it does not actually need to be handled in modern runtimes. Refs: * https://stackoverflow.com/a/52613818/595220 * https://peps.python.org/pep-0475/ * python/cpython#56671 * https://stackoverflow.com/a/38258781/595220 * https://docs.python.org/3/library/exceptions.html#InterruptedError * python/cpython#36893
`IOError` is an alias of `OSError` since Python 3.3. Python 3 also indroduced a new exception `InterruptedError` which represents `EINTR`. The `time.sleep()` call could raise IOError: [Errno 4] Interrupted function call on KBInt under Python 2, which would be `InterruptedError` under Python 3 but it's not raised anymore post PEP 475 that was implemented in Python 3.5. So it does not actually need to be handled in modern runtimes. Refs: * https://stackoverflow.com/a/52613818/595220 * https://peps.python.org/pep-0475/ * python/cpython#56671 * https://stackoverflow.com/a/38258781/595220 * https://docs.python.org/3/library/exceptions.html#InterruptedError * python/cpython#36893
`IOError` is an alias of `OSError` since Python 3.3. Python 3 also indroduced a new exception `InterruptedError` which represents `EINTR`. The `time.sleep()` call could raise IOError: [Errno 4] Interrupted function call on KBInt under Python 2, which would be `InterruptedError` under Python 3 but it's not raised anymore post PEP 475 that was implemented in Python 3.5. So it does not actually need to be handled in modern runtimes. Refs: * https://stackoverflow.com/a/52613818/595220 * https://peps.python.org/pep-0475/ * python/cpython#56671 * https://stackoverflow.com/a/38258781/595220 * https://docs.python.org/3/library/exceptions.html#InterruptedError * python/cpython#36893
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: