Should I close after popen??

Ken Seehof kens at sightreader.com
Fri Mar 16 13:41:31 EST 2001


----- Original Message ----- 
From: "Donn Cave" <donn at oz.net>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Friday, March 16, 2001 12:13 AM
Subject: Re: Should I close after popen??

> . . .
> Files normally (in C Python, anyway) close implicitly when they
> go out of scope and no reference to them remains in the system.
> There's nothing wrong with an explicit close, though, and in
> popen() files it also releases the process slot, which until
> then (or until the parent's exit)  will appear as a "zombie".
> 
> Donn Cave, donn at oz.net
> -- 
> http://mail.python.org/mailman/listinfo/python-list

More specifically, they close when garbage collected, which
is at some unknown time -after- they go out of scope and no
reference to them ramains on the system.  Usually this distinction
doesn't matter, but there are some cases where this can get you
into trouble, and the result could be a nasty intermittent bug.

In general, never rely on destructor timing in python.  It was ok
in C++, but it won't always work in python.

- Ken






More information about the Python-list mailing list