Can signal.alarm be safely cleared in python?

dieter dieter at handshake.de
Fri Nov 18 03:51:20 EST 2016


Pedro Franco de Carvalho <reddopp at gmail.com> writes:

> Assume a python program sets a handler function for the
> `signal.SIGALRM` signal, and then schedules an alarm in T seconds with
> `signal.alarm(T)`.
>
> Assume the program later cancels any scheduled alarm with `signal.alarm(0)`.

I do not think so. You might have a "race condition".

I think of the following (hypothetical) situation: the alarm
arrives while "signal.alarm(0)" processing has started but not yet finished.
In this case, the alarm arrival will schedule the alarm handler
activation - but, as "signal.alarm" is "C" implemented, the handler
will not be activated immediately (but delayed until the next
execution of Python code).




More information about the Python-list mailing list