Bugs item #1603150, was opened at 2006-11-26 10:59 Message generated for change (Comment added) made by polivare 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: Patricio Olivares (polivare) Date: 2007-03-15 00:08 Message: Logged In: YES user_id=1413642 Originator: NO Simple patch added: [1681153] ---------------------------------------------------------------------- Comment By: Patricio Olivares (polivare) Date: 2007-03-14 23:57 Message: Logged In: YES user_id=1413642 Originator: NO wave.open expects either a str or a file object. When it gets a str, it opens the file, works on it, and closes the file. All of this in the inner scope of the wave.open function. But if the file pointed by the str is not a correct wav format, then wave.open throws wave.Error but *doesn't close the file*. It assumes that the file will be garbage collected and then closed but that does not happen. I believe that it has to do with the "Note" at <http://docs.python.org/ref/customization.html#l2h-177> The problem is noted mostly on the interactive interpreter on windows because on windows you can't delete/move a file if it's being used by another process so you need to close the interpreter to release the file. ---------------------------------------------------------------------- Comment By: A.M. Kuchling (akuchling) Date: 2006-12-19 16: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com