Author biosthezerg
Recipients biosthezerg
Date 2020-09-09.13:00:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The standard `wave` library tries to close a file unconditionally. I believe this is wrong.

From the docs:
Wave_write.close(): Make sure nframes is correct, and close the file if it was opened by wave. *This method is called upon object collection.* [...]

This leads to problems when an exception is throw when a file is open. See the following MWE:
from io import BytesIO
import wave
audio_out = BytesIO() 
with, "w") as file_out:
    raise Exception('aaa!') 

Error: # channels not specified

Even when I remove the context manager, so it shouldn't close the file automatically, it still does, the following:
file_out =, "w")
raise Exception('aaa!')
doesn't throw an error at me immediately, but when the file_out variable is running out of scope, I get a printout saying: `Exception ignored in: <bound method Wave_write.__del__ of <wave.Wave_write object at 0x7ff549064eb8>> [...] wave.Error: # channels not specified`.

Expected behaviour: When I use a Wave_write object as a context manager, it tries to close the file unconditionally (as it does now). When I call `` manually, no automatic file closing is done.
Date User Action Args
2020-09-09 13:00:36biosthezergsetrecipients: + biosthezerg
2020-09-09 13:00:36biosthezergsetmessageid: <>
2020-09-09 13:00:36biosthezerglinkissue41752 messages
2020-09-09 13:00:36biosthezergcreate