473,785 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(c md, capturestderr = True)
popen3.tochild. close()

strOutput = ''
strErrors = ''
fdOutputFrom = popen3.fromchil d.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.remo ve(fd)
popen3.fromchil d.close()
popen3.childerr .close()
return popen3.wait(), strOutput, strErrors
Dec 21 '06 #1
0 1617

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

Similar topics

2
7592
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 = os.popen3('/usr/local/adapt/bin/descmng -g') o.write('\n%s\n\n' % (redpick)) o.close() time.sleep(1)
4
1811
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 metacharaters by constructing a command line. Basically, I want something that acts just like Popen3 but allows me to specify cmd as a path + args. Does something like this exist in the standard library? If not, it sounds like a good candidate...
1
2101
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 = r'"C:\Handheld\SC10\GFSDK\dev\Drivers\CE.EVC4\GFHAL\GFHAL.Vcp"' config = "GFHAL - Win32 (WCE ARMV4) Release"
13
4461
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 close the returned files and all is good. (I'm not trying to communicate with the program via popen3 and so had been using os.spawnlp, but that doesn't exist on Windows.)
1
5274
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 javascript. Currently I am using the meta tag as default, no refresh:
2
2042
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 attribute, which I use to kill the auxiliary program when necessary. Popen3 does not exist on Windows. I see os.popen2 and os.popen3, but they provide only file objects for stdin, stdout, and stderr so I don't see a way to kill the auxiliary program...
2
2690
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 os.popen3() hanging under Windows in this group before. I stumbled on a case where a piece of code works in some occasions and hangs consistently given different data. It performs exactly the same on 3 different computers running Windows:
4
782
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There is no built-in way to pause execution in javascript such as a sleep function, but hosts usually provide a method of some form. Web browsers are designed for event driven programming and only provide the « setTimeout » and « setInterval »...
3
1729
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 first select is project and i am asking user to select it by using <?php $sql = "SELECT ProjectName FROM ProjectDetails"; "ORDER BY ProjectName"; $rs = mysql_query($sql); ...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.