I’m using a recipe that relies on SIGALRM to set alarm interrupt —
Using module 'subprocess' with timeout
The problem is that I have more than one Python script using signal.ALARM process to set time-outs, and only the latest alarm gets called. What is a good way to improve this multiple Python functions setting time-outs?
Except for simple, quick hacks, avoid SIGALRM. It’s a very old, limited mechanism, not suited to anything more complex: you can only set a single alarm, and it interrupts any system call at the time rather than just the one you intend to interrupt.
It’s much cleaner to use a timeout thread to kill the process, for example:
Depending on what you’re timing out, you may want to use a lighter signal than SIGKILL to allow the timing-out process to clean up after itself.