473,783 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.cl ose()
self.fromchild. close()
if self.childerr:
self.childerr.c lose()
try:
os.kill(self.pi d,15)#SIGTERM - ASK NICELY
except OSError:
os.kill(self.pi d,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 3110
In article <ma************ *************** *********@pytho n.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.washingt on.edu
Jul 18 '05 #2

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

Similar topics

4
8765
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 still running. I tried the popen2 module for that: self.pp = popen2.Popen3(cmd)
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)
1
1712
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: """Test program to demonstrate problem with popen2 module.""" import popen2 def main (argv): mycmd = 'python2.3 -c "for i in range(100000):\n print i"' p = popen2.Popen3(mycmd)
1
2590
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 exit status of the child process if it has finished, or -1 if it hasn't finished yet.""" if self.sts < 0: try: pid, sts = os.waitpid(self.pid, os.WNOHANG)
3
1551
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 plays music as it should... Any ideas?
2
4171
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: win32pipe.popen2() win32pipe.popen3() win32pipe.popen4() while win32pipe.popen() does almost what you want.
11
584
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
1597
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
1617
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 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
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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
10081
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
9946
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
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
5378
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.