Issue1468

classification
Title: close not called immediately
Type: behaviour Severity: normal
Components: Core Versions: 2.5.0
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, pjenvey, ssteiner, zyasoft
Priority: Keywords:

Created on 2009-09-14.15:40:25 by ssteiner, last changed 2009-10-20.04:29:36 by pjenvey.

Messages
msg5158 (view) Author: simon steiner (ssteiner) Date: 2009-09-14.15:40:24
Failing to call close() delays the file being written while ant may
depend on the file being read. This is working correctly for python and jep.

<script language="jython" setbeans="false">
<![CDATA[
import os
os.remove('x')
f = open('x', 'w')
f.write('xyz')
#f.close()
]]>
</script>
<loadfile property="message" srcFile="x"/>
<echo message="${message}"/>
</target>
msg5159 (view) Author: Jim Baker (zyasoft) Date: 2009-09-14.15:47:32
Can you please provide more context why this is a bug for Jython?

Implementations of languages providing garbage collection without ref 
counting do not provide immediate destruction upon a ref going out of 
scope. This can exhaust resources that are linked to objects, such as 
file resource, or leave them hanging until one or more phases of GC has 
run.

Instead it's necessary to ensure that the resource is closed as soon as 
possible. We recommend you use something like the following:

f = open(...)
try:
    do_something_with_it(f)
finally:
    f.close()

or alternatively

with open(...) as f:
    do_something_with_it(f)
msg5160 (view) Author: Jim Baker (zyasoft) Date: 2009-09-14.15:52:38
I should have made this more clear:

If we are shipping code that doesn't do this close as indicated, we have 
a bug in Jython. We found a number of these in the standard library, or 
especially tests of the stdlib.

But if there's code in some third component that's not performing the 
close, it's a bug in that system.
msg5161 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-09-14.16:45:01
Note too that the way to do this in Python implementations 2.5 and up is

from __future__ import with_statement
with open('x', 'w') as f:
    f.write('xyz')
msg5239 (view) Author: Philip Jenvey (pjenvey) Date: 2009-10-20.04:29:34
AFAICT not a bug, closing out. Please reopen if there's another underlying 
issue involved
History
Date User Action Args
2009-10-20 04:29:36pjenveysetstatus: open -> closed
resolution: invalid
messages: + msg5239
nosy: + pjenvey
2009-09-14 16:45:01fwierzbickisetnosy: + fwierzbicki
messages: + msg5161
2009-09-14 15:52:38zyasoftsetmessages: + msg5160
2009-09-14 15:47:32zyasoftsetnosy: + zyasoft
messages: + msg5159
2009-09-14 15:40:25ssteinercreate