Getting happier ;-), but wondering if I'm thinking pythonically

Erik Max Francis max at alcyone.com
Wed May 21 01:46:18 EDT 2003


Brian Quinlan wrote:

> How so? Unless the file object is participating in a cyclic data
> structure, when will it not be collected?

Python as language does not declare precisely when objects will be
reclaimed, and indeed doesn't even guarantee that they will in all cases
(even discounting cyclic data structures).  An obvious example of this
is Jython -- a completely legitimate Python implementation -- which uses
Java's native garbage collector to invoke __del__ methods.  You've no
guarantee that opened files in Jython (or any other Python
implementation) will be closed in a timely manner after the last
reference to the file object goes away.

Just as in Java, important external resources need to be handled
carefully in Python.  The native CPython implementation tends to call
destructor methods quickly -- so you might be getting away with it --
but you've no guarantee in Python as a general language will.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ The graveyards are full of indispensible men.
\__/  Charles de Gaulle




More information about the Python-list mailing list