Skip to content

Commit d5813cf

Browse files
committed
Merge branch 'gather-to-zarr' into extract-waveforms-to-zarr
2 parents 03b617c + 8ddf404 commit d5813cf

3 files changed

Lines changed: 20 additions & 22 deletions

File tree

‎src/spikeinterface/core/binaryrecordingextractor.py‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,6 @@ def get_binary_description(self):
156156
)
157157
return d
158158

159-
def __del__(self):
160-
"""
161-
Ensures that all segment resources are properly cleaned up when this recording extractor is deleted.
162-
Closes any open file handles in the recording segments.
163-
"""
164-
# Close all recording segments
165-
for segment in self.segments:
166-
# This will trigger the __del__ method of the BinaryRecordingSegment
167-
# which will close the file handle
168-
del segment
169-
170159

171160
BinaryRecordingExtractor.write_recording.__doc__ = BinaryRecordingExtractor.write_recording.__doc__.format(
172161
_shared_job_kwargs_doc

‎src/spikeinterface/core/sortinganalyzer.py‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,10 +2969,16 @@ def __init__(self, sorting_analyzer):
29692969
self.data = dict()
29702970

29712971
def __del__(self):
2972+
# Ensure open memmap file handles are released when the extension is garbage collected.
2973+
# Best-effort: __del__ must never raise.
2974+
self._release_data_file_handles()
2975+
2976+
def _release_data_file_handles(self):
29722977
# Close any open memmap file handles held in `data` (e.g. when an extension gathers or
29732978
# loads its data as a memmap). On Windows an open memmap prevents deleting the underlying
2974-
# file, so releasing the handles here allows the extension folder to be removed when the
2975-
# extension is dropped (e.g. on recompute). Best-effort: __del__ must never raise.
2979+
# file, so releasing the handles allows the extension folder to be removed (e.g. on
2980+
# recompute). This closes the file handle but leaves the (now unusable) array object and any
2981+
# non-memmap data in `data` untouched.
29762982
data = self.__dict__.get("data", None)
29772983
if not data:
29782984
return
@@ -3478,12 +3484,14 @@ def _reset_extension_folder(self):
34783484
Delete the extension in a folder (binary or zarr) and create an empty one.
34793485
"""
34803486
if self.format == "binary_folder":
3481-
# Drop the analyzer's reference to a previously computed extension of the same name so
3482-
# it can be garbage collected. Its __del__ releases any open file handles (e.g. a memmap
3483-
# kept in `data` when gathering directly to npy) which, on Windows, would otherwise
3484-
# prevent deleting the folder below.
3485-
old_extension = self.sorting_analyzer.extensions.pop(self.extension_name, None)
3486-
del old_extension
3487+
# Release open file handles (e.g. a memmap kept in `data` when gathering/extracting
3488+
# directly to npy) of a previously computed extension of the same name. On Windows an
3489+
# open memmap would otherwise prevent deleting the folder below. We deliberately do NOT
3490+
# remove it from `self.sorting_analyzer.extensions` nor clear its data: some extensions
3491+
# (e.g. metrics) read the previous extension back during their computation.
3492+
old_extension = self.sorting_analyzer.extensions.get(self.extension_name, None)
3493+
if old_extension is not None and old_extension is not self:
3494+
old_extension._release_data_file_handles()
34873495

34883496
extension_folder = self._get_binary_extension_folder()
34893497
if extension_folder.is_dir():

‎src/spikeinterface/postprocessing/template_similarity.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ def _compute_similarity_matrix_numba(
341341
tgt_sliced = other_templates_array[:, num_shifts + shift : num_samples - num_shifts + shift]
342342

343343
for i in prange(num_templates):
344-
src_template = src_sliced[i]
345-
overlapping_ids = overlapping_j_list[i]
346-
overlapping_chs = active_channels_list[i]
344+
i_ = np.int64(i)
345+
src_template = src_sliced[i_]
346+
overlapping_ids = overlapping_j_list[i_]
347+
overlapping_chs = active_channels_list[i_]
347348

348349
for pair_idx in range(len(overlapping_ids)):
349350
j = np.uint16(overlapping_ids[pair_idx])

0 commit comments

Comments
 (0)