[2.7] bpo-30807: signal.setitimer() may disable the timer by mistake (GH-2493) (#2499)
* bpo-30807: signal.setitimer() may disable the timer by mistake
* Add NEWS blurb.
(cherry picked from commit 729780a810bbcb12b245a1b652302a601fc9f6fd)
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 1d7ba4b..c7bf1f0 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -111,6 +111,10 @@
{
tv->tv_sec = floor(d);
tv->tv_usec = fmod(d, 1.0) * 1000000.0;
+ /* Don't disable the timer if the computation above rounds down to zero. */
+ if (d > 0.0 && tv->tv_sec == 0 && tv->tv_usec == 0) {
+ tv->tv_usec = 1;
+ }
}
Py_LOCAL_INLINE(double)