Skip to content

Commit c6513c2

Browse files
authored
fix timeout issue (#35)
1 parent cf2f6a2 commit c6513c2

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# read the contents of your README file
44
from pathlib import Path
5+
56
this_directory = Path(__file__).parent
67
long_description = (this_directory / "README.md").read_text()
78

@@ -12,7 +13,7 @@
1213
license="MIT",
1314
description="Python iterator for safely monitoring NeXus files",
1415
long_description=long_description,
15-
long_description_content_type='text/markdown',
16+
long_description_content_type="text/markdown",
1617
author="Diamond Light Source Ltd",
1718
author_email="scientificsoftware@diamond.ac.uk",
1819
url="https://github.com/DiamondLightSource/python-swmrtools",

swmr_tools/datasource.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
from .utils import get_position, create_dataset, append_data
55
import sys
6+
from time import sleep
67

78
try:
89
import blosc
@@ -123,19 +124,14 @@ def __iter__(self):
123124

124125
def __next__(self):
125126

126-
if self.kf.is_finished():
127-
raise StopIteration
127+
current_dataset_index = next(self.kf)
128128

129-
else:
130-
131-
current_dataset_index = next(self.kf)
129+
output = SliceDict()
132130

133-
output = SliceDict()
131+
self._add_datasets_to_output(current_dataset_index, output)
132+
self._add_interleaved_datasets_to_output(current_dataset_index, output)
134133

135-
self._add_datasets_to_output(current_dataset_index, output)
136-
self._add_interleaved_datasets_to_output(current_dataset_index, output)
137-
138-
return output
134+
return output
139135

140136
def _add_datasets_to_output(self, current_dataset_index, output):
141137
if self.dataset_paths is None:
@@ -312,7 +308,15 @@ def get_frame_direct(self, ds, pos, rank, slices):
312308
for i in range(len(pos)):
313309
chunk_pos[i] = pos[i]
314310

315-
out = ds.id.read_direct_chunk(chunk_pos)
311+
try:
312+
out = ds.id.read_direct_chunk(chunk_pos)
313+
except Exception:
314+
# let the file system catch up
315+
sleep(1)
316+
if hasattr(ds, "refresh"):
317+
ds.refresh()
318+
out = ds.id.read_direct_chunk(chunk_pos)
319+
316320
decom = blosc.decompress(out[1])
317321
a = np.frombuffer(decom, dtype=ds.dtype, count=-1)
318322
return a.reshape(self.chunk), tuple(slices[: self.scan_rank])

0 commit comments

Comments
 (0)