How to set sigalarm to repeat over and over again in linux?
<p>I'm trying to make alarm work over and over again.</p>

<p>My handler is</p>

<pre><code>def handler_SIGALRM(signum, frame):
    print "waiting"
    signal.alarm(2)
</code></pre>

<p>The alarm work only once, even though every time I set it again.
In my code I also use sigchld and sys.exit after the child working.</p>

<p>I'm running it with cygwin.</p>

<p>EDIT:
I need to write a code that will print "waiting" every second, with sigalarm and not loops</p>

<p>I'm an idiot, I edited the wrong code</p>

<p>You put your <code>signal.alarm(2)</code> in a wrong place. See my example below.</p>

<pre><code>import time
import signal

class TimeoutException (Exception):
    pass

def signalHandler (signum, frame):
    raise TimeoutException ()

timeout_duration = 5

signal.signal (signal.SIGALRM, signalHandler)




for i in range (5):
    signal.alarm (timeout_duration)
    try:
        """Do something that has a possibility of taking a lot of time 
        and exceed the timeout_duration"""
        time.sleep (20)
    except TimeoutException as exc:
        print "Notify your program that the timeout_duration has passed"
    finally:
        #Clean out the alarm
        signal.alarm (0)
</code></pre>

python cygwin signals posix