Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82427

How to make subprocess run for 60 sec?

Date 2014-12-12 14:18 +0530
Subject How to make subprocess run for 60 sec?
From Robert Clove <cloverobert@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16900.1418374098.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

How to make subprocess run for 60 sec? Robert Clove <cloverobert@gmail.com> - 2014-12-12 14:18 +0530

csiph-web