473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

13 second delay using select() with Popen3()

hi all...

I wrote a seemingly simple function (below) to use Popen3() and select()
to run a program and capture its exit status, stdout output, and stderr
output.

It worked fine until the box was upgraded to Debian sarge.
Now the call to select() always takes about 13 seconds before returning
the first time.
The delay only occurs when the function is running within a CGI program
invoked by Apache (v2.2).
If I run the same thing from a shell in the same environment, there is
no delay.
The correct result is always returned; the only problem is the 13-second
delay.

The command passed as "cmd" runs a bash script which looks at some local
files and prints one line of output and then does "exit 0".
Python is v2.4.4 (can't use 2.5 because I am using Zope which doesn't
support it yet).

I would appreciate any suggestions or advice about whether I got the
select loop wrong somehow, or what else might be wrong. Thanks!!

Jonathan Mark
-------
import os, popen2, select

def execCommand(cmd, mergeErrors = False):
popen3 = popen2.Popen3(cmd, capturestderr = True)
popen3.tochild.close()

strOutput = ''
strErrors = ''
fdOutputFrom = popen3.fromchild.fileno()
fdlistFrom = [fdOutputFrom, popen3.childerr.fileno()]
while fdlistFrom:
fdlistReadable, fdlistWriteable, fdlistError = select.select(
fdlistFrom, [], fdlistFrom)
for fd in fdlistError:
raise AssertionError('file I/O error with child process')
for fd in fdlistReadable:
data = os.read(fd, 8192)
if data:
if mergeErrors or fd is fdOutputFrom:
strOutput += data
else:
strErrors += data
else:
fdlistFrom.remove(fd)
popen3.fromchild.close()
popen3.childerr.close()
return popen3.wait(), strOutput, strErrors
Dec 21 '06 #1
0 1578

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rajarshi Guha | last post by:
Hi, I have some code that runs an interactive program via popen3(). The program generates output which is then used later on. My script looks like this: o,i,e =...
4
by: Chris Green | last post by:
Hey folks, I'm whipping up a quick CGI to wrap a command line app and I was a bit suprised to not find a execl-like Popen3 style object. I don't want to bother with the shell interpreting...
1
by: Ruchika | last post by:
Hi, I want to build an embedded Visual C++ project from the python script. This is what I do - evc = r'"C:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\Bin\EVC.EXE"' proj =...
13
by: Russell E. Owen | last post by:
I'm trying to launch an application from Python 2.3 on Windows. The application is "ds9" (an image viewer), and is installed in C:\Program Files\ds9\ds9 On unix I just do: os.popen3("ds9") and...
1
by: Troy | last post by:
Hello- I have a need to allow a user to reload a page on a chosen interval (selected from a select box) or to chose not to reload the page at all (default). I would like to do this in...
2
by: Jeffrey Barish | last post by:
I have an application that has been working fine on Linux, but now I need to port it to Windows XP. The program uses Popen3 to run another program. I use Popen3 so that I can access the pid...
2
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There...
3
by: micky125 | last post by:
Hey guys I have been checking the forum for a way to populate a second select field depending on the choice made from the first one. Basically i am working on projects and the delays that occur. The...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.