Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'output': 0.05; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'sec': 0.16; 'subject:make': 0.16; 'subject:run': 0.16; 'all,': 0.19; 'command': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'file.': 0.24; 'script': 0.25; 'pass': 0.26; 'message-id:@mail.gmail.com': 0.30; 'pipe': 0.31; 'run': 0.32; 'skip:# 10': 0.33; 'received:google.com': 0.35; 'subject:?': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'signal': 0.60; 'skip:o 30': 0.61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=hJgG9ewiEnpuomzjGvoF0FgnifNeXgXPZ1MIQb+/p50=; b=kc0X5DzcbiFftrtFq+WLfebtPRCcwnPAnc5Vwz7WnQA8ljvmFC3T/bsIOSqdNSkguD +71ft9A9/JrJkUgqlL2HD34FoQJuTDu9hY/VXpH/x1CuRFDtgTQSurigZJA+lafCBf5A 9TLF46hbQ+khePS211IMpPDVu5+Booj3OzZKbqS0KKTUxWrq5FUEiDhra89rDY3scA7O JAsIYlhBD18QUOcPZW4xeYEYDlvSpDxXZkQ4U05ZYYjsDCPw4x3W67GB+IIjArD9uRya wfswo6nFMWirTVIXwUCFDMYxdExzHoXx0v9UQ0LfxzSwOidKshYHwIUt/gKpe8XOs56r 48LQ== MIME-Version: 1.0 X-Received: by 10.202.48.82 with SMTP id w79mr8892487oiw.30.1418374089313; Fri, 12 Dec 2014 00:48:09 -0800 (PST) Date: Fri, 12 Dec 2014 14:18:09 +0530 Subject: How to make subprocess run for 60 sec? From: Robert Clove To: "python-list@python.org" Content-Type: multipart/alternative; boundary=001a113cda36c09749050a00f3b9 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418374098 news.xs4all.nl 2887 [2001:888:2000:d::a6]:49908 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82427 --001a113cda36c09749050a00f3b9 Content-Type: text/plain; charset=UTF-8 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 --001a113cda36c09749050a00f3b9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi All,

I have the following python= script that runs.
I want is to run the subprocess to run for 60 s= ec and then send the SIGINT signal to subprocess and write the output in fi= le.

#!/usr/bin/python
import os
import subproce= ss
PIPE =3D subprocess.PIPE
import signal
import time

def h= andler(signum, frame):
=C2=A0=C2=A0=C2=A0 pass

signal.signal(sign= al.SIGALRM, handler)
signal.alarm(60)
command =3D "strace -c ./s= erver"
os.chdir("/root/Desktop/")
p =3D subprocess.Pop= en(command, stdout=3DPIPE, stderr=3DPIPE)
time.sleep(60)
p.send_signa= l(signal.SIGINT)
signal.alarm(0)
print p.communicate()[1]


=
Regards

--001a113cda36c09749050a00f3b9--