python-soundfile icon indicating copy to clipboard operation
python-soundfile copied to clipboard

Test if closefd argument works

Open mgeier opened this issue 10 years ago • 3 comments
trafficstars

mgeier avatar Jan 24 '15 13:01 mgeier

From what I can see, closefd doesn't work at all. For example:

>>> import soundfile as sf
>>> f=open('test.wav', 'rb')
>>> ff = sf.SoundFile(f)
>>> f.closed
False
>>> ff.closed
False
>>> ff.close()
>>> ff.closed
True
>>> f.closed
False

This is from a test I did on the trunk.

tgarc avatar Jan 15 '17 19:01 tgarc

The closefd argument is not supposed to have an effect if you use file-like objects.

It only comes into action if you use file descriptors. In Python you can get them for example with os.open(), but probably also from some external libraries. You can get the underlying file descriptor of a Python file object with the fileno() method, but I don't know what happens to the file object if you close its file descriptor ...

BTW, this functionality is not implemented in Python, it is a feature of the libsndfile library itself.

mgeier avatar Jan 15 '17 20:01 mgeier

Okay, I suspected that I wasn't understanding this feature correctly. I see now, thanks.

tgarc avatar Jan 16 '17 00:01 tgarc