python: what's wrong with my subprocess.Popen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting python: what's wrong with my subprocess.Popen
# 1  
Old 12-18-2010
python: what's wrong with my subprocess.Popen

my script is
Code:
#!/usr/bin/env python
import datetime
import subprocess
import sys
import os
import signal
from time import sleep
def runForAWhile(cmd, secs=10):
 print("running %s" % cmd)
 timeout = datetime.timedelta(seconds=secs)
 print timeout
 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
 status = proc.poll()
 start = datetime.datetime.now()
 while (status is None and (datetime.datetime.now() - start) <
timeout): #not timed out
     #print proc.stdout.readline() #TODO timestamp?
 print status
     #print datetime.datetime.now() - start
 if 0 == status:
     print("'%s' is program exited" %cmd)
 else:
     try:
         os.kill(proc.pid, signal.SIGINT)
     print "Process timeout: '%s'" % cmd
     except OSError:
         pass
cmd="ping 128.224.165.20 -c 4"
runForAWhile(cmd,30)

Why "status' is aways !=0, ----> the program is NOT exit?

Lei

Last edited by yanglei_fage; 12-19-2010 at 01:54 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Python] - subprocess issue

So I have this basic script, see below import subprocess import shlex command = "gcloud projects list" subprocess.check_output(shlex.split(command)) subprocess.check_call(shlex.split(command)) The subprocess.check_call(shlex.split(command)) actually return what I expect. It returns... (6 Replies)
Discussion started by: scj2012
6 Replies

2. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./oop.py", line 20, in <module> y = DerivedClass("Manu") File "./oop.py", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies

3. Shell Programming and Scripting

Subprocess.popen() should write to log without waiting for process to complete

Here is my test code process = sp.Popen( + , bufsize=1, universal_newlines=True, stdout=sp.PIPE, stderr=sp.STDOUT, cwd=src_home) output, _ =... (2 Replies)
Discussion started by: ezee
2 Replies

4. Shell Programming and Scripting

Python - Function print vs return - whats wrong

All, I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this #!/usr/bin/python def div4and6(s,e): for i in range(s,e+1): if... (5 Replies)
Discussion started by: oky
5 Replies

5. Shell Programming and Scripting

Python subprocess

Hi guys, I'm learning python and perl and i was trying to run from python a perl script using the subprocess module. I have an issue that i don't understand regarding this. I run this code: #!/usr/bin/python import subprocess p2 = subprocess.Popen(,stdout=subprocess.PIPE) output2 =... (2 Replies)
Discussion started by: capitanui
2 Replies

6. Shell Programming and Scripting

Xterm using python subprocess

Hi, I am trying to run a shell script using subprocess in python. I can run simple script with arguments using subprocess.But I am not able to embed xterm in subrocess command. #!/usr/bin/python import subprocess subprocess.call() Above code gives me error. Please help me in... (2 Replies)
Discussion started by: diehard
2 Replies

7. Shell Programming and Scripting

Python subprocess module

I need to run this command using python subprocess module (notice I'm using only variables): cmd = TESTPATH + ' -s ' + serviceName + ' -r ' + rdir + \ ' -m ' + masterAcct + ' -p ' + persona + ' -P ' + passwd (3 Replies)
Discussion started by: erick_tuk
3 Replies

8. AIX

Subprocess errors

Hi Guys, Just a question about subprocesses.. Lately one of our servers has started to throw out the following error: SYSTEM ERROR: Too many subprocesses, cannot fork. Errno=12 We've already increased the threshold twice. Its now up to 8000 and the swap space has also been increased. We... (6 Replies)
Discussion started by: Jazmania
6 Replies

9. Shell Programming and Scripting

Doubt about pipes and subprocess

Hi, I am having a trivial doubt. Please see the below pipeline code sequence. command1 | (command 2; commend 3) I am aware that the command that follows pipe will run in the sub shell by the Unix kernel. But how about here? Since these set of commands are grouped under "parantheses", will... (6 Replies)
Discussion started by: royalibrahim
6 Replies

10. Shell Programming and Scripting

Python: popen problems

Hello I'm writing a web server in python(obelisk-http.sourceforge.net) and I'm having a greeat problem with POST method it like that When someone make a POST request to the server it must open the executable(perl/python/.exe/elf) and send to the STANDART in (stdin) the request and get the... (2 Replies)
Discussion started by: sendai
2 Replies
Login or Register to Ask a Question
evolution-addressbook-import(1) 				   User Commands				   evolution-addressbook-import(1)

NAME
evolution-addressbook-import - import contact information into the local address book in Ximian Evolution, Sun Microsystems Edition SYNOPSIS
evolution-addressbook-import [--help] [--input=input-file] [--usage] [--version] DESCRIPTION
Import contact information into the local address book from a file. The file contents can be in either virtual-card (Vcard) format or comma-separated value (CSV) format. OPTIONS
The following options are supported: --help Display help text. You can also use -? to specify this option. --input=input-file Specify the input file that contains the information to be imported. --usage Display brief usage text. --version Display version information. EXAMPLES
Example 1: Importing Contact Information into Local Address Book From contacts.vcf example% evolution-addressbook-import --input=contacts.vcf EXIT STATUS
The following exit values are returned: 0 Application exited successfully 1 Application exited with failure FILES
The following files are used by this application: /usr/bin/evolution-addressbook-import Executable to import data into Evolution local address book $HOME/evolution Per-user configuration files and local storage for Evolution $HOME/evolution/mail/account/folders Temporary files for Evolution mail $HOME/evolution/sunone/account/folders Temporary files for Evolution Sun ONE account ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Architecture |SPARC | +-----------------------------+-----------------------------+ |Availability |SUNWevo | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT safe with Exceptions | +-----------------------------+-----------------------------+ SEE ALSO
Ximian Evolution Sun Microsystems Edition User Guide evolution(1), evolution-address-export(1) NOTES
Written by Steven Zhang, Sun Microsystems Inc., 2004. SunOS 5.10 15 Apr 2004 evolution-addressbook-import(1)