I have the code below in a Python module; it uses subprocess to start a command line app and reads the output the app writes to stdout.
If the command line app doesn't complete after 15 seconds, I want the code to time out. I have used signal.alarm to try to achieve this.
When testing the module without Django it times out after 15s as expected. However, when I call the code from a Django view it doesn't timeout after 15s, but continues to run until the spawned process times out.
How can I get this to do what I want?
p = get_process() # spawns a process using subproccess and returns the process handle
signal.signal(signal.SIGALRM, alarm_handler)                           
signal.alarm(15)   
try:
    s= p.stdout.read()
except:
    p.kill()
    s = "Operation timed out"
 
     
     
    