-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BinaryRecordingExtractor opens the binary file, but doesn't close it, preventing later deleting or modifying binary file #3295
Comments
@cheydrick have you tried |
Ah, that did release it and allowed the file to be deleted. I had first tried setting I'll close this issue and pick up the discussion in the PR. |
I'm going to re-open this issue to note that deleting the recording object does not release the file if Kilosort 4 is first run. For example:
I can't tell if it's something within the run_sorter() code or within Kilosort itself that's holding on to the file. I haven't yet tried it with other sorters. |
KS4 makes its own file handle which is likely a different reference than the |
Perhaps, though when I modified the BinaryRecordingSegment class to open the .bin file only when it needs it, and close right afterwards, the problem went away (#3296). If KS4 was also opening the file, this modification wouldn't have changed anything, right? Maybe there's something in BaseSorter or Kilosort4Sorter that's making a copy of the BinaryRecordingExtractor class instance, which means deleting the original may do nothing. |
Hi @cheydrick , I am looking for where the |
This is the Kilosort version of our extractor. They read straight from our extractors just without any mutliprocessing. So I think we would actually need to read their code to see how they really interact with any of our extractors. |
Maybe this part: though I haven't read it too closely recently: |
Mmm but I don't think that's the case. Otherwise, the changes to |
You could be right. I'm just spit-balling. But for me it would be nice to have a little clarity. Is this only happening with KS4 or is this happening running any sorter that relies on binary recordings (so KS2,2.5,3). Or even MS5 would stay in python and uses a binary recording in its most recent iteration. |
Do our sorters rely on |
Yeah, so the load_recording_from_folder will load the class of the file. So since we write the binary then during loading it reloads the extractor as a binary recording. As far as I know. |
I just ran my test program on my Linux machine (I had been using Windows 11) and can't replicate the problem. I can run Kilosort4, and can then delete the .bin file without needing to manually delete the recording object. FYI. |
This is the classic file release issue between Linux and Windows. Windows tries to eagerly do the deletion and Linux just puts it in the queue to be deleted later. So this is something that we constantly struggle with on all versions of Windows. I'm on a windows work station for lab and I've just come up with the workarounds I need for it. |
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:
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.
The text was updated successfully, but these errors were encountered: