Multi-threading with a simple timer?

Marko Rauhamaa marko at pacujo.net
Tue Jul 3 10:05:32 EDT 2018


Gregory Ewing <greg.ewing at canterbury.ac.nz>:

> Robin Becker wrote:
>> if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then
>> the timeout function gets called anyway.
>
> Yes, it needs some more stuff around it to make it useful. Probably
> you also want the signal handler to raise an exception and catch it
> somewhere rather than exiting the process.

My advice: stay away from (non-terminal) signals. They are a primitive
communication scheme that *might* have had uses in the early 1970's.

At the time signals were part of so-called "asynchronous programming."
The pattern called for the main routine to have:

    for (;;)
        pause()

and *everything* in the program was done in signal handlers.

Unless you do *everything* in signal handlers, you should do *nothing*
in signal handlers.


Marko


More information about the Python-list mailing list