Skip to content

Parallel downloads into the same pooch cache - #381

Merged
g5t merged 1 commit into
mccode-dev:mainfrom
tkittel:pooch-parallel-download-race
Oct 9, 2026
Merged

g5t merged 1 commit into
mccode-dev:mainfrom
tkittel:pooch-parallel-download-race

Conversation

@tkittel

@tkittel tkittel commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Trying to add a second mccode-antlr notebook for the NCrystal example notebook website caused a CI failure which was tracked down to a race condition in the cache dir creation. There is an open PR to fix this in pooch itself, but the workaround on the mccode-antlr side is trivial, so would be nice to have it added here already.

Claude says:

When several processes download into the same pooch cache (e.g. two notebooks or test jobs running at the same time), one of them can fail when both need a component directory which does not exist yet. pooch (at least up to 1.9.0) creates the directory of a downloaded file without exist_ok, so the slower process fails. On Windows it shows up as:

Arm not found in registries: libc,mcstas; every registry that knew of it failed to provide it:
  mcstas: [WinError 183] Cannot create a file when that file already exists: '...\mccodeantlr\mcstas\Cache\v3.9.2\mcstas-comps\optics'

This is a known pooch bug (fatiando/pooch#555), fixed upstream by the pooch PR fatiando/pooch#554, which is not merged yet. Until a pooch release contains it, the registries now fetch through a small helper, pooch_fetch(), which first creates the directory itself, with exist_ok. The helper can be removed again once mccode-antlr requires a pooch version with that fix, but it is fine to simply keep it.

The new test downloads 100 files into new directories with 8 processes from a local HTTP server, so it needs no network and takes about a second. Without the workaround it failed in every run (also on Linux).

🤖 Generated with Claude Code

pooch (at least up to 1.9.0) creates the directory of a file it downloads
without exist_ok, so when several processes download into the same cache, one
fails if another creates the directory at the same time
(fatiando/pooch#555, open fix in
fatiando/pooch#554). On Windows the error is
"[WinError 183] Cannot create a file when that file already exists".

The registries now fetch through pooch_fetch(), which creates the directory
first, with exist_ok. The new test downloads 100 files into new directories
from a local HTTP server with 8 processes: without the workaround, some
downloads fail in every run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@g5t
g5t merged commit f0f420c into mccode-dev:main Oct 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants