[Tutor] popen2.Popen4 objects

Jeff Shannon jeff@ccvcorp.com
Mon Aug 4 15:12:02 EDT 2003


klappnase wrote:

>Seems to work all fine, however I found that after the child process has finished, the Popen4 instance
>still persists:
>
>  
>
>>>>print self.pp
>>>><popen2.Popen4 instance at 0x834d1fc>
>>>>        
>>>>
>
>I think it sould be removed somehow, but I don't know how to do that. I'd be very thankful for any help.
>  
>

An object exists as long as there are references to it.  In most cases, 
that's a good thing -- for instance, there may be information about the 
terminated process that you want to get later.  However, if you're sure 
that you're done with it, you can remove the reference to it that you've 
saved.  You can do this in one of two ways.  You can set self.pp = None, 
which cause your Popen4 object to be decref'ed, which will presumably 
allow it to be garbage-collected (if this is the only reference to it). 
 Your parent object (self) will still have a pp attribute, but it will 
point to None.  You could also 'del self.pp', which removes the pp 
attribute completely (thus also decref'ing the Popen4 object and 
probably garbage-collecting it).  Which of these is preferable depends 
on what else you're doing with your parent object -- in the second case, 
attempting to reference self.pp will result in an AttributeError, while 
in the first case it yields None.  This could be useful for conditionals 
("if self.pp: do_something()").

Jeff Shannon
Technician/Programmer
Credit International






More information about the Tutor mailing list