Should I close after popen??

Jeremy Hylton jeremy at alum.mit.edu
Fri Mar 30 14:39:56 EST 2001


>>>>> "FP" == =?iso-8859-1?q?Fran=E7ois?= Pinard <pinard at iro.umontreal.ca> writes:

  FP> [David Bolen]
  >> pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard)
  >> writes:

  >> > I would completely agree with the above for someone who wants
  >> > to write Jython, or write Python that could be quickly turned
  >> > into Jython.  But if you stick with Python, you can safely rely
  >> > on the fact that a file is automagically closed as soon as you
  >> > do not refer to it anymore.

  >> I'd probably change Python in that sentence to CPython, since
  >> it's an implementation issue and not a language one (the language
  >> makes no such guarantees).

  FP> As it was pointed on this list quite a while ago, Python has no
  FP> language definition per itself.  It is rather defined by the
  FP> documentation of its main implementation. 

Yes and no.  I believe the language reference is intended to define
the language, not the implementation.  It may not be perfect in this
regard, but the language reference is not just "the documentation of
its main implementation."
 
  FP>                                            It is true that the
  FP> documentation of (C)Python does not commit it on the particular
  FP> issue above, and this is why I checked with this list before
  FP> starting to firmly rely on this feature, in real code.

I believe there is an FAQ entry about finalization.  The official
position is that immediate finalization via reference counting is not
part of the language definition.  It's just a property of a particular
implementation.  I'd recommend calling close explicitly; I believe
that is what the FAQ says.

However, I don't expect CPython to change any time soon.  (But who
knows what changes are lurking unforseen :-).

Jeremy




More information about the Python-list mailing list