How to make subprocess run for 60 sec?

Robert Clove cloverobert at gmail.com
Fri Dec 12 03:48:09 EST 2014


Hi All,

I have the following python script that runs.
I want is to run the subprocess to run for 60 sec and then send the SIGINT
signal to subprocess and write the output in file.

#!/usr/bin/python
import os
import subprocess
PIPE = subprocess.PIPE
import signal
import time

def handler(signum, frame):
    pass

signal.signal(signal.SIGALRM, handler)
signal.alarm(60)
command = "strace -c ./server"
os.chdir("/root/Desktop/")
p = subprocess.Popen(command, stdout=PIPE, stderr=PIPE)
time.sleep(60)
p.send_signal(signal.SIGINT)
signal.alarm(0)
print p.communicate()[1]


Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141212/a2f57c8e/attachment.html>


More information about the Python-list mailing list