Message376634
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. |
|
Date |
User |
Action |
Args |
2020-09-09 13:00:36 | biosthezerg | set | recipients:
+ biosthezerg |
2020-09-09 13:00:36 | biosthezerg | set | messageid: <1599656436.68.0.838572818257.issue41752@roundup.psfhosted.org> |
2020-09-09 13:00:36 | biosthezerg | link | issue41752 messages |
2020-09-09 13:00:36 | biosthezerg | create | |
|