Should I close after popen??

Donn Cave donn at oz.net
Fri Mar 16 20:12:48 EST 2001


Quoth "Ken Seehof" <kens at sightreader.com>:
[ re files close after last reference ]
| 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.

That's the party line, since the Java implementation can't
finalize on reference counts and for that matter there's no
guarantee that the C implementation always will.

But at present it does.  In C Python, you may rely on destructor
timing if you want, it will happen exactly when it should.
The garbage collection option that was introduced in 2.0 does
not change that.  You have to understand that it's not official,
but it's so useful that it's hard to pretend it isn't there.

	Donn Cave, donn at oz.net



More information about the Python-list mailing list