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.

Author biosthezerg
Recipients biosthezerg
Date 2020-09-09.13:00:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599656436.68.0.838572818257.issue41752@roundup.psfhosted.org>
In-reply-to
Content
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 wave.open(audio_out, "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 = wave.open(audio_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 `wave.open` manually, no automatic file closing is done.
History
Date User Action Args
2020-09-09 13:00:36biosthezergsetrecipients: + biosthezerg
2020-09-09 13:00:36biosthezergsetmessageid: <1599656436.68.0.838572818257.issue41752@roundup.psfhosted.org>
2020-09-09 13:00:36biosthezerglinkissue41752 messages
2020-09-09 13:00:36biosthezergcreate