cross platform alternative for signal.SIGALRM?

Marko Rauhamaa marko at pacujo.net
Thu Nov 12 01:14:48 EST 2015


Terry Reedy <tjreedy at udel.edu>:

> The cross-platform 3.4 asyncio module has some functions with
> timeouts.

Even that doesn't forcefully interrupt an obnoxious blocking function
call like

   time.sleep(10000)

The original question claimed signal.alarm() would do the trick in
Linux. However, even that cannot be relied on as "man alarm" states:

   sleep(3) may be implemented using SIGALRM; mixing calls to alarm()
   and sleep(3) is a bad idea.

I'm thinking the only portable way is to run a watchdog process with
subprocess or multiprocessing.


Marko



More information about the Python-list mailing list