File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,6 +148,18 @@ def get_binary_description(self):
148148 )
149149 return d
150150
151+ def __del__ (self ):
152+ """
153+ Ensures that all segment resources are properly cleaned up when this recording extractor is deleted.
154+ Closes any open file handles in the recording segments.
155+ """
156+ # Close all recording segments
157+ if hasattr (self , "_recording_segments" ):
158+ for segment in self ._recording_segments :
159+ # This will trigger the __del__ method of the BinaryRecordingSegment
160+ # which will close the file handle
161+ del segment
162+
151163
152164BinaryRecordingExtractor .write_recording .__doc__ = BinaryRecordingExtractor .write_recording .__doc__ .format (
153165 _shared_job_kwargs_doc
@@ -223,6 +235,15 @@ def get_traces(
223235
224236 return traces
225237
238+ def __del__ (self ):
239+ # Ensure that the file handle is closed when the segment is garbage-collected
240+ try :
241+ if hasattr (self , "file" ) and self .file and not self .file .closed :
242+ self .file .close ()
243+ except Exception as e :
244+ warnings .warn (f"Error closing file handle in BinaryRecordingSegment: { e } " )
245+ pass
246+
226247
227248# For backward compatibility (old good time)
228249BinDatRecordingExtractor = BinaryRecordingExtractor
Original file line number Diff line number Diff line change 2525 CenterRecording ,
2626 center ,
2727)
28+
2829from .scale import scale_to_uV
2930
3031from .whiten import WhitenRecording , whiten , compute_whitening_matrix
You can’t perform that action at this time.
0 commit comments