-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-30807: signal.setitimer() now uses _PyTime API #3865
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
Conversation
The _PyTime API handles detects overflow and is well tested.
Modules/clinic/signalmodule.c.h
Outdated
@@ -168,7 +168,7 @@ signal_siginterrupt(PyObject *module, PyObject **args, Py_ssize_t nargs) | |||
#if defined(HAVE_SETITIMER) | |||
|
|||
PyDoc_STRVAR(signal_setitimer__doc__, | |||
"setitimer($module, which, seconds, interval=0.0, /)\n" | |||
"setitimer($module, which, seconds, interval=None, /)\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any point in changing the default to None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, it wasn't my intent. I fixed it.
Document that the signal will only be sent once if internal is equal to zero.
Doc/library/signal.rst
Outdated
|
||
When an interval timer fires, a signal is sent to the process. | ||
The signal sent is dependent on the timer being used; | ||
:const:`signal.ITIMER_REAL` will deliver :const:`SIGALRM`, | ||
:const:`signal.ITIMER_VIRTUAL` sends :const:`SIGVTALRM`, | ||
and :const:`signal.ITIMER_PROF` will deliver :const:`SIGPROF`. | ||
|
||
If *interval* is equal to zero, the signal will only be sent once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it's correct to promise that the signal will be sent. If seconds is in the past (using ITIMER_REAL), the signal is never sent, no?
Maybe I should replace "and after that every interval seconds" with "and after that every interval seconds (if interval is not equal to zero)" instead? What do you think @pitrou?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to POSIX, setitimer
should return EINVAL when a negative argument is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> signal.setitimer(signal.ITIMER_REAL, 0, -1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
signal.ItimerError: [Errno 22] Invalid argument
>>> signal.setitimer(signal.ITIMER_REAL, -1, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
signal.ItimerError: [Errno 22] Invalid argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand correctly your comments. Do you mean that setitimer() warrants that at least one signal will be fired?
I changed the documentation to not overspecify Python since Python is just a thin wrapper to the system setitimer() function. I just added "(if interval is non-zero)" to the existing doc.
The _PyTime API handles detects overflow and is well tested.
https://bugs.python.org/issue30807