Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Oct 13, 2017
Merged

bpo-30807: signal.setitimer() now uses _PyTime API #3865

merged 3 commits into from
Oct 13, 2017

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 3, 2017

The _PyTime API handles detects overflow and is well tested.

https://bugs.python.org/issue30807

The _PyTime API handles detects overflow and is well tested.
@@ -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"
Copy link
Member

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.

Copy link
Member Author

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.

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.
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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.

@vstinner vstinner merged commit ef611c9 into python:master Oct 13, 2017
@vstinner vstinner deleted the setitimer_pytime branch October 13, 2017 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants