Skip to content
Advertisement

Why is SIGALARM killing the Python program on Linux?

import signal
import time
import multiprocessing as mp


def launch():
    signal.alarm(5)
    while True:
            time.sleep(1)
            print "Alive"

p = mp.Process(target=launch)
p.start()
p.join()

This programs prints Alive four times on stdout and then dies. While I am not handling the SIGALARM signal explicitly inside the program, I just expect the alarm to get ignored. However, on Linux, the script dies after the alarm is triggered. I have not been able to find any documentation for Linux which states that it should be the default behavior for the alarm signal. Any idea what is causing this behavior?

Advertisement

Answer

From the man pages, it’s pretty clear that this is expected. Under the “Standard Signals” section, the default action for SIGALRM is to terminate the process. This is the case on any of the Unix-like environments I’m aware of.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement