Issue229320

classification
Title: can't delete file when file is left open
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: bckfnn, thehaas
Priority: normal Keywords:

Created on 2001-01-18.23:11:14 by thehaas, last changed 2001-02-25.16:21:25 by bckfnn.

Messages
msg258 (view) Author: Mike Hostetler (thehaas) Date: 2001-01-18.23:11:14
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).

msg259 (view) Author: Mike Hostetler (thehaas) Date: 2001-01-19.03:28:17
I'm obsessed - can't you tell??

Actually, here is an article that describes the Unix side of it . .. . it explains the IEEE standard of unlinking files.

http://www.itl.nist.gov/div897/staff/barkley/titleissues/node26.html
msg260 (view) Author: Finn Bock (bckfnn) Date: 2001-02-25.16:21:25
Logged In: YES 
user_id=4201

In reallity we have no choice on the matter. The file is 
kept open due to the GC nature of java and the operating 
systems are defining whether deleting an open file is 
allowed. As such the different behaviour is here to stay.
History
Date User Action Args
2001-01-18 23:11:14thehaascreate