[ python-Bugs-1180237 ] Python keeps file references after calling close methode

SourceForge.net noreply at sourceforge.net
Thu Apr 14 21:50:46 CEST 2005


Bugs item #1180237, was opened at 2005-04-10 10:20
Message generated for change (Comment added) made by jepler
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1180237&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Eelco (eternia)
Assigned to: Nobody/Anonymous (nobody)
Summary: Python keeps file references after calling close methode

Initial Comment:
I found this bug using a python script that:

- first mounts a partition  (os.system("mount") etc)
- change a few files on this partition (f = open ();
f.write; f.close)
- umounts the partition (os.system("umount") etc)

Strangely, the umount didn't work because of a
filesystem busy error. Using fuser and lsof i traced
this being busy back to the script itself. This is
strange behavior because after changing the files on
the mounted partition the close method was called which
should close all references to the file on the partition. 

Finally the solution was to do f = 0. So if python has
closed a file on a mount a open reference to that file
will keep to exist until the script has ended or until
the file object is nullified.





----------------------------------------------------------------------

Comment By: Jeff Epler (jepler)
Date: 2005-04-14 14:50

Message:
Logged In: YES 
user_id=2772

I tried but can't reproduce this problem.

After mounting a filesystem on /mnt/tmp, I ran the following
in an interactive session:
>>> f = open("/mnt/tmp/x", "w")
>>> f.write("testing")
>>> f.close()
>>> import os; os.system("umount /mnt/tmp")
0

Did you write 'f.close()' or 'f.close'?  The former closes
the file, but the latter is a statement which has no effect.
 When you later executed 'f=0', the reference count of
the-old-value-of-f dropped to 0 and the file was close()d
impliclty.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1180237&group_id=5470


More information about the Python-bugs-list mailing list