Skip to content

Commit e4b3732

Browse files
committed
add reading attempts
1 parent bd1e006 commit e4b3732

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

neo/rawio/plexon2rawio/plexon2rawio.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,19 @@ def __init__(self, filename, pl2_dll_file_path=None):
128128

129129
self.pl2reader = PyPL2FileReader(pl2_dll_file_path=pl2_dll_file_path)
130130

131-
# Open the file.
132-
self.pl2reader.pl2_open_file(self.filename)
133-
134-
if not (platform.system() == "Linux"):
131+
reading_attempts = 3
132+
for attempt in range(reading_attempts):
133+
self.pl2reader.pl2_open_file(self.filename)
134+
135135
# Verify the file handle is valid.
136-
if self.pl2reader._file_handle.value == 0:
137-
self.pl2reader._print_error()
138-
raise Exception(f"Opening {self.filename} failed.")
136+
if self.pl2reader._file_handle.value != 0:
137+
# File handle is valid, exit the loop early
138+
break
139+
else:
140+
if attempt == reading_attempts - 1:
141+
self.pl2reader._print_error()
142+
raise IOError(f"Opening {self.filename} failed after {reading_attempts} attempts.")
143+
139144

140145
def _source_name(self):
141146
return self.filename

0 commit comments

Comments
 (0)