fileobj.write(buffer(...))

David Bolen db3l at fitlinxx.com
Fri Feb 23 19:39:20 EST 2001


"Alexander Semenov" <sav at ulmen.mv.ru> writes:

> No, python python implements reference counting. Then file object loose all
> references it will del-ed. I think file object handles del correctly and
> closes
> corresponding handle.

Just as a general point, you can't guarantee when _del_ will be
called.  While the current CPython implementations (even in 2.x I
think) trigger that when the RC hits zero, there's no guarantees, and
it might not be called until later (or even until Python's process
terminates).  I'm not sure if JPython/Jython does it immediately even
in their current releases.

So depending on the criticality of controlling the close, you may want
to handle it yourself explicitly, particularly if you are writing data
that might otherwise not get flushed until (possibly) much later.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list