|
3 | 3 | import numpy as np |
4 | 4 | from .utils import get_position, create_dataset, append_data |
5 | 5 | import sys |
| 6 | +from time import sleep |
6 | 7 |
|
7 | 8 | try: |
8 | 9 | import blosc |
@@ -123,19 +124,14 @@ def __iter__(self): |
123 | 124 |
|
124 | 125 | def __next__(self): |
125 | 126 |
|
126 | | - if self.kf.is_finished(): |
127 | | - raise StopIteration |
| 127 | + current_dataset_index = next(self.kf) |
128 | 128 |
|
129 | | - else: |
130 | | - |
131 | | - current_dataset_index = next(self.kf) |
| 129 | + output = SliceDict() |
132 | 130 |
|
133 | | - output = SliceDict() |
| 131 | + self._add_datasets_to_output(current_dataset_index, output) |
| 132 | + self._add_interleaved_datasets_to_output(current_dataset_index, output) |
134 | 133 |
|
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 |
139 | 135 |
|
140 | 136 | def _add_datasets_to_output(self, current_dataset_index, output): |
141 | 137 | if self.dataset_paths is None: |
@@ -312,7 +308,15 @@ def get_frame_direct(self, ds, pos, rank, slices): |
312 | 308 | for i in range(len(pos)): |
313 | 309 | chunk_pos[i] = pos[i] |
314 | 310 |
|
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 | + |
316 | 320 | decom = blosc.decompress(out[1]) |
317 | 321 | a = np.frombuffer(decom, dtype=ds.dtype, count=-1) |
318 | 322 | return a.reshape(self.chunk), tuple(slices[: self.scan_rank]) |
|
0 commit comments