[ python-Bugs-1603150 ] wave module forgets to close file on exception

SourceForge.net noreply at sourceforge.net
Tue Dec 19 20:59:08 CET 2006


Bugs item #1603150, was opened at 2006-11-26 08:59
Message generated for change (Comment added) made by akuchling
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1603150&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: amerinese (amerinese)
Assigned to: Nobody/Anonymous (nobody)
Summary: wave module forgets to close file on exception

Initial Comment:
I am using python 2.4 on Windows XP SP2

The wave module function:
f = wave.open(file)

In the case that file is a path to the file and the file is not yet opened, wave.open(file) may raise an exception if the file is opened and it does not fulfill the format of a WAV file.  However, it forgets to close the file when the exception is raised keeping other functions from accessing the file (at least until the file is garbage collected).

The regular file opening idiom doesn't work
f = wave.open(file)
try:
   ## do something with the wav file
finally:
   f.close()
Since wave.open(file) raises an exception before return the file name, f can't be closed, but the file is open.

The reason I know this is because I try to delete the file if trying to open it raises an RIFF or not a WAV file exception and it claims the file is locked.

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

>Comment By: A.M. Kuchling (akuchling)
Date: 2006-12-19 14:59

Message:
Logged In: YES 
user_id=11375
Originator: NO

Try putting the Wave.open() inside the try...finally.



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

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


More information about the Python-bugs-list mailing list