|
From: <no...@so...> - 2001-01-18 23:11:10
|
Bug #129320, was updated on 2001-Jan-18 15:11
Here is a current snapshot of the bug.
Project: Jython
Category: None
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: thehaas
Assigned to : nobody
Summary: can't delete file when file is left open
Details: This is related to a bug I submitted a month or so ago. You guys
rightfully closed it, but I finally nailed down what was causing it. There
should be at least be a note somewhere in the documentation about it. I'm
not sure it can be fixed.
I know, technically, you should always close your files. But what if you
don't? In CPython, if you don't close your files when opening them in a
function, the garbage collector closes it for you. But there has been some
inconsisencies in how Jython behaves.
Here is my test:
import os,tempfile
def writeFile(fileName,str):
file = open(fileName,"w")
file.write(str)
# I'm not closing the file on purpose
if __name__ == '__main__':
fileName = "bugtest.tmp"
str = "Frank Burns eats worms\n"
writeFile(fileName,str)
os.remove(fileName)
This works fine on CPython on Windows 2000 and Solaris as well as Jython
2.0 on Solaris, but not with Jython 2.0 on Windows 2000. On Windows 2000,
it gives this exception:
Traceback (innermost last):
File "bug.py", line 16, in ?
File "C:\jython-2.0\Lib\javaos.py", line 44, in remove
OSError: [Errno 0] couldn't delete file: 'bugtest.tmp'
In reality, I think the behavior on Windows 2000 is the correct one, but
the choice is up to you. We did some research here, and this really does
go down to the C level. Following is an example, which we compiled with
gcc on Solaris, gcc on Cygwin, and lc (the line compiler with Visual
Studio).
#include <stdio.h>
int main() {
FILE *f;
f=fopen("tempfile","r");
if(f != NULL) {
printf("File is Open\nAttempting to Delete...");
}
if(remove("tempfile")!=0) {
printf("Delete Failed\n");
} else {
printf("Delete Successful (Solaris Sucks)\n");
}
}
With both versions of gcc, this file was deleted. With lc, the delete
failed. (Obviously, the file "tempfile" needs to be created before running
this).
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=129320&group_id=12867
|