This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wave module forgets to close file on exception
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: amerinese, georg.brandl
Priority: normal Keywords:

Created on 2006-11-26 15:58 by amerinese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30672 - (view) Author: amerinese (amerinese) Date: 2006-11-26 15:58
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.
msg30673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-11-26 16:01
Duplicate of #1603150.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44276
2006-11-26 15:58:21amerinesecreate