> On 1 Sep 2019, at 17:57, MRAB <pyt...@mrabarnett.plus.com> wrote:
>
> On 2019-09-01 16:46, Barry wrote:
>>> On 31 Aug 2019, at 15:41, Manfred Lotz <ml_n...@posteo.de> wrote:
>>> When you say COULD this sounds like it is a matter of luck. My thinking
>>> was that USUALLY the file will be closed after the statement because
>>> then the file handle goes out of scope.
>> It all depends on the way any python implementation does its garbage
>> collection. The file is closed as a side effect of deleting the file object
>> to reclaiming the memory of the file object.
>> At the start of python 3 people where suprised when files and other
>> resources where not released at the same time that python 2 released them.
> Is that true?
Yes. I recalling having to fix some code, but that was over 10 years ago.
I have been using python 3 since the alphas of 3.0.
>
> I thought that it was because other implementations of Python, such as Jython
> and IronPython, don't use reference counting, so files and other resources
> aren't necessarily released as soon as an object loses its last reference,
> and, moreover, it's not required to do so by the language definition.
You can also see delayed rsource freeing with cpython. I think it was
an fd leak and lsof showed the files where not closing. Adding with fixed it.
But it was so long ago...
>
> Adding the 'with' statement added determinism.
Barry
>
> See PEP 343 -- The "with" Statement
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list