Skip to content

BinaryRecordingExtractor opens the binary file, but doesn't close it, preventing later deleting or modifying binary file #3295

Open
@cheydrick

Description

@cheydrick

I attempted to programmatically delete a .bin file I had used after performing operations using a BinaryRecordingExtractor object, but was getting an exception saying that the file was in use by another process.

Brief pseudo-code example:

# create BinaryRecordingExtractor instance
recording = si.read_binary("file.bin", num_channels=256, sampling_frequency=40000, dtype='int16')
# Perform an operation
recording.save_to_folder(folder='saved', overwrite=True)
# attempting to delete the .bin file fails
os.remove(binfile) 

I found that the BinaryRecordingSegment class (used within BinaryRecordingExtractor) opens the binary file when it's instanced, but never closes it.

I moved the file open operation to the get_traces() method, wrapping the relevant code in a 'with open()' statement, which fixed the problem. I will submit a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreChanges to core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions