Author pjcreath
Recipients pjcreath
Date 2011-01-07.16:23:41
SpamBayes Score 8.8651e-11
Marked as misclassified No
Message-id <>
Calling wave.close() fails to release all references to the file passed in via, "rb").  As a result, processing many wave files produces an IOError of too many files open.

This bug is often masked because this dangling reference is collected if the wave object is collected.  However, if the wave object is retained, calling wave_obj.close() won't release the reference, and so the file will never be closed.

There are two solutions:

1) The workaround: the client program can explicitly close the file object it passed to the wave object ("file_obj.close()").

2) The bug fix: the wave module can properly release the extra reference to the file, by setting "self._data_chunk = None" in the close() method.  Explanation:

Trunk code (and 2.7.1, and older):

    def close(self):
        if self._i_opened_the_file:
            self._i_opened_the_file = None
        self._file = None

but note initfp(self, file):
        self._file = Chunk(file, bigendian = 0)
                chunk = Chunk(self._file, bigendian = 0)
                self._data_chunk = chunk

therefore close needs to add:

        self._data_chunk = None
Date User Action Args
2011-01-07 16:23:45pjcreathsetrecipients: + pjcreath
2011-01-07 16:23:44pjcreathsetmessageid: <>
2011-01-07 16:23:42pjcreathlinkissue10855 messages
2011-01-07 16:23:41pjcreathcreate