473,473 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

popen hangs sporadically

kj



I have a script that calls the function write_tmpfile, which looks
something like this:

def write_tmpfile(f, tmpfile):
# set-up code omitted
in_f = popen("""grep -v '^\\[eof\\]$' %s |\
grep '[^[:space:]]' |\
sort -u""" % f)
out_f = open(tmpfile, 'w')
try:
while 1:
line = in_f.readline()
if not line: break
# i omit the code that munges line
out_f.write(line)
finally:
in_f.close()
out_f.close()

The script calls this function several thousand times. (The average
size of the input file f is 70K lines (0.5MB); the maximum size is
about 35M lines, or 200MB.) This function works perfectly most of
the time, but it deadlocks sporadically. (And it's a deadlock!
The script can be stuck for hours, until I kill it.)

I can't say for sure where the deadlock is happening (and I'd
appreciate suggestions on how to pinpoint this), but I *think* it
is at the in_f.readline() statement. So maybe the problem is with
the pipe. (But FWIW, I've used exactly the same pipe in another
script that processes the same set of files (but does not write a
temporary file when it does this), and this script terminates
without any problem. I.e. the input files are not too large for
the pipe.)

I suppose that I could use some timeout mechanism to unwedge the
script when it deadlocks and then repeat the call to write_tmpfile,
but I'd prefer to avoid the deadlock in the first place.

I'd appreciate suggestions on how to troubleshoot and debug this
thing.

TIA!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Aug 1 '08 #1
0 777

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

Similar topics

0
by: Byrom, R (Rob) | last post by:
hi, When I use: os.popen('ssh -l root@something tomcat4 stop') I find the command always hangs. The 'something' host contains the correct key in the authorized_hosts file and works ok on the...
0
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: Maarten van Veen | last post by:
A long story made short, I've build a python/cgi website consisting of two pages. Page1 has a html form in which you can input a series of queries. Then via Popen it starts a pythons search script,...
6
by: gregpinero | last post by:
Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() while 1: pass And I want to call it from another Python process and read the value 'hi'. How...
1
by: Marko Rauhamaa | last post by:
This tiny program hangs: ======================================================================== #!/usr/bin/env python import subprocess a = subprocess.Popen('cat',shell = True,stdin =...
1
by: Jean-Paul Calderone | last post by:
On Mon, 12 May 2008 17:35:44 -0700 (PDT), schickb <schickb@gmail.comwrote: Alas, you haven't actually closed src's standard input. Though you did close src.stdin, you didn't close the copy of it...
0
by: Kenneth McDonald | last post by:
When making calls of the form Popen(cmd, shell=True, stdout=subprocess.PIPE), we've been getting occasional, predictable hangs. Will Popen accumulate a certain amount of stdout and then block...
0
by: Christian Heimes | last post by:
Kenneth McDonald wrote: The subprocess module has already an API method for your use case. The communicate() method of a subprocess.Popen instance takes an optional stdin string and returns the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.