Skip to content

Commit 539be06

Browse files
authored
avoid error when 2 threads fetch the same dataset at the same time (#1658)
1 parent 5fae545 commit 539be06

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

skrub/datasets/_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,16 @@ def _extract_archive(dataset_dir, archive_path):
274274
temp_dir = tempfile.mkdtemp(dir=dataset_dir)
275275
shutil.unpack_archive(archive_path, temp_dir, format="zip")
276276
path_source = Path(temp_dir) / dataset_name
277-
path_source.rename(dataset_dir / dataset_name)
277+
path_target = dataset_dir / dataset_name
278+
try:
279+
path_source.rename(path_target)
280+
except OSError: # pragma: nocover
281+
if path_target.is_dir():
282+
# another thread was fetching the dataset at the same time and
283+
# beat us to it; no problem
284+
return
285+
else:
286+
raise
278287
except (Exception, KeyboardInterrupt):
279288
try:
280289
archive_path.unlink()

0 commit comments

Comments
 (0)