Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82427 > unrolled thread
| Started by | Robert Clove <cloverobert@gmail.com> |
|---|---|
| First post | 2014-12-12 14:18 +0530 |
| Last post | 2014-12-12 14:18 +0530 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
How to make subprocess run for 60 sec? Robert Clove <cloverobert@gmail.com> - 2014-12-12 14:18 +0530
| From | Robert Clove <cloverobert@gmail.com> |
|---|---|
| Date | 2014-12-12 14:18 +0530 |
| Subject | How to make subprocess run for 60 sec? |
| Message-ID | <mailman.16900.1418374098.18130.python-list@python.org> |
[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 top | Article view | comp.lang.python
csiph-web