473,372 Members | 814 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,372 software developers and data experts.

popen2.Popen3 process destruction

This could possibly be a bug, but I don't understand it fully
so I'm posting here first. Searching the list told me other
people are having this problem too.

I have created a class which inherits popen2.Popen3.

The problem is that popen2.Popen3 does not define a __del__
method to handle proper closing of the pipes or destruction of
the process. So I created one in my class:

def __del__(self):
self.tochild.close()
self.fromchild.close()
if self.childerr:
self.childerr.close()
try:
os.kill(self.pid,15)#SIGTERM - ASK NICELY
except OSError:
os.kill(self.pid,9)#SIGKILL - BE RELENTLESS

However, since the popen2 module stores a reference to the
object in popen2._active this __del__ method is never called
to clean things up. _cleanup() called in Popen3.__init__()
fails to clean up the process in subsequent instantiations.
This eventually leads to an "OSError: [Errno 24] Too many open
files"

"_clean()" fails because the program being called is
interactive using stdin/stdout. Much in the way "cat" is. In
fact the unit test provided with the popen2 module _test()
uses "cat" and hangs for the very same reason. It hangs on
"for inst in _active[:]:inst.wait()" This is why I created my
own class, to handle this special interactive nature.

The only workaround I currently see is ripping all but the
"_active.append(self)" from the popen2.Popen3.__init__() code
and putting it in my __init__. Currently I just call it
directly as prescribed by the python reference manual.

Perhaps I'm missing the epiphany of why _active and _cleanup()
are needed and not a __del__() method.

Thanks,
-Brian

System info:
IRIX64 6.5
Python 2.2.3

Jul 18 '05 #1
1 3087
In article <ma************************************@python.org >,
<br****@temple.edu> wrote:
I have created a class which inherits popen2.Popen3.

The problem is that popen2.Popen3 does not define a __del__
method to handle proper closing of the pipes or destruction of
the process. So I created one in my class: .... However, since the popen2 module stores a reference to the
object in popen2._active this __del__ method is never called
to clean things up. _cleanup() called in Popen3.__init__()
fails to clean up the process in subsequent instantiations.
This eventually leads to an "OSError: [Errno 24] Too many open
files"
The instance needs to keep itself around, to work with popen2
and popen3 functions and generally support direct use of the
pipe fileobjects and file descriptors.
"_clean()" fails because the program being called is
interactive using stdin/stdout. Much in the way "cat" is. In
fact the unit test provided with the popen2 module _test()
uses "cat" and hangs for the very same reason. It hangs on
"for inst in _active[:]:inst.wait()" This is why I created my
own class, to handle this special interactive nature.


That is not normal, that I know of - test_open2.py's use
of cat should not cause a hang. Unless we're looking at
very different versions of test_popen2.py. I wonder if
there could be a problem somewhere in the IRIX64
implementation of Python, or in the OS itself.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #2

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

Similar topics

4
by: klappnase | last post by:
Hello, everyone, I am running python2.2.2 on a linux box. I want to call a shell command and get the PID of this child process so I have the possibility to abort the child process while it is...
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 =...
1
by: A. Lloyd Flanagan | last post by:
OK, I've got a weird one I haven't been able to figure out yet. Admittedly I haven't had time to dig into the library source, but this behavior certainly doesn't seem right. Here's a test case: ...
1
by: Jeffrey Barish | last post by:
Popen3 provides the method poll() which returns the exit status of the child process if it has finished or -1 if the process is still running. Here is the code: def poll(self): """Return the...
3
by: alexrait1 | last post by:
I launch my python. Then I write this: import popen2 popen2.Popen3("mplayer *.mpg") it starts playing for 2 seconds.. and then stops... if I quit python (ctrl - D) mplayer continues to run and...
2
by: Jakob Simon-Gaarde | last post by:
Follow-up on a thread from 1999 (see below) Well now it is 2005 and the operating system I'm using is Windows Server 2003, and I can still see that the same problem persists with: ...
11
by: g.franzkowiak | last post by:
I start a process in my application with popen2.popen3('MyOtherProcess'). That's ok, but what can I do if the other process is running ? Can I fetch some information and start with that ? gerd
1
by: mikem76 | last post by:
Is there a way to get the process id when starting a process using os.popen2 or os.popen3 on linux? Mike
0
by: Jonathan Mark | last post by:
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...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.