Skip to content

Commit 47b09a7

Browse files
committed
Fix race condition handling in apply registration task
1 parent 99074da commit 47b09a7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

fractal_tasks_core/tasks/apply_registration_to_image.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,34 @@ def apply_registration_to_image(
205205
# Get the relevant metadata of the Zarr table & add it
206206
# See issue #516 for the need for this workaround
207207
max_retries = 20
208-
sleep_time = 5
208+
sleep_time = 10
209209
current_round = 0
210210
while current_round < max_retries:
211211
try:
212212
old_table_group = zarr.open_group(
213213
table_dict[table], mode="r"
214214
)
215215
current_round = max_retries
216-
except zarr.errors.GroupNotFoundError:
216+
curr_table = ad.read_zarr(table_dict[table])
217+
break # Exit loop on success
218+
except (
219+
zarr.errors.GroupNotFoundError,
220+
zarr.errors.PathNotFoundError,
221+
):
217222
logger.debug(
218223
f"Table {table} not found in attempt {current_round}. "
219224
f"Waiting {sleep_time} seconds before trying again."
220225
)
221226
current_round += 1
222227
time.sleep(sleep_time)
228+
else:
229+
# This runs only if the loop exits via exhaustion
230+
raise RuntimeError(
231+
f"Table {table} not found after {max_retries} attempts."
232+
"Check whether this table actually exists. If it does, "
233+
"this may be a race condition issue."
234+
)
223235
# Write the Zarr table
224-
curr_table = ad.read_zarr(table_dict[table])
225236
write_table(
226237
new_image_group,
227238
table,

0 commit comments

Comments
 (0)