popen e pclose on python 2.3 question

F

Flyzone

I need to run a network program and return output in a variable name
without use temporany file.
So i tought to use popen (i'm using python 2.3, i can't upgrade).
RESULT = os.popen('command'+HOST, 'r')
I have a problem about it:
i need to kill the child if the program take more than 300 ms, but i
need also to wait this 300 ms to have the reply.
os.pclose(RESULT) give me:
AttributeError: 'module' object has no attribute 'pclose'
cause pclose doens't exist in 2.3.....and a time.wait(0.3) is not a so
clean code.
Someone can give me some tricks? I would like a script portable on
python 2.3, i would not like
to compile on 2.5.
 
F

Flyzone

i need to kill the child if the program take more than 300 ms, but i
need also to wait this 300 ms to have the reply.

I reply by myself:

from popen2 import Popen3
cmd = Popen3('command','r')
waiting=0
while (cmd.poll()==-1):
time.sleep(0.1)
waiting+=1
if (waiting>3): os.kill(RESULT.pid,0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,133
Latest member
MDACVReview
Top