Skip to content

Commit 5421f09

Browse files
committed
enh: robuster NFS lock for download of DIPY data on GHA
1 parent 45839b8 commit 5421f09

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/test_motion_viz.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323

2424
from pathlib import Path
25+
from time import sleep
2526

2627
import numpy as np
2728
import pandas as pd
@@ -39,9 +40,26 @@
3940
plot_volumewise_motion,
4041
)
4142

42-
if not (Path.home() / ".dipy" / "stanford_hardi").exists():
43+
# Folders are atomic operations in NFS, therefore, creating folders is a good
44+
# way to implement rudimentary semaphores/locks.
45+
# OE: we are running into race conditions for the way dipy downloads data.
46+
# The delayed creation of the "stanford_hardi" directory makes this test
47+
# for data existence very flaky.
48+
# Replacing with a pure lock based on directory creation.
49+
dipy_datapath = Path.home() / ".dipy"
50+
if not (lock_folder := dipy_datapath / ".lock-stanford_hardi").exists():
51+
lock_folder.mkdir(parents=True)
4352
fetch_stanford_hardi()
4453

54+
MAX_CHECKS = 20
55+
try_num = 1
56+
while not (dipy_datapath / "stanford_hardi").exists():
57+
sleep(5 * try_num)
58+
try_num += 1
59+
60+
if try_num > MAX_CHECKS:
61+
raise RuntimeError("Error downloading DIPY's stanford_hardi dataset")
62+
4563
img, _ = read_stanford_hardi()
4664
img_data = img.get_fdata()
4765

0 commit comments

Comments
 (0)