Skip to content

Use exist_ok when creating directory in stream_download - #554

Open
wpbonelli wants to merge 2 commits into
fatiando:mainfrom
wpbonelli:stream-download-exist-ok
Open

wpbonelli wants to merge 2 commits into
fatiando:mainfrom
wpbonelli:stream-download-exist-ok

Conversation

@wpbonelli

Copy link
Copy Markdown

Avoid FileExistsError when stream_download is called by multiple processes

Relevant issues/PRs:
Same idea as #171 just a different code path

@wpbonelli

Copy link
Copy Markdown
Author

Looks like style checks are failing on main too, unrelated to these changes.

@wpbonelli
wpbonelli marked this pull request as ready for review September 20, 2026 11:15
wpbonelli added a commit to MODFLOW-ORG/modflow-devtools that referenced this pull request Sep 20, 2026
Pooch can produce FileExistsError when concurrent workers (e.g. pytest-xdist) try to create the same new subdirectory. Create the directory first with exist_ok=True so pooch's existence check passes. See fatiando/pooch#554

Also place the lock file in the cache directory next to the zip file it protects, rather than in the cwd, so it excludes processes regardless of their working directory and does not litter it.
tkittel added a commit to tkittel/mccode-antlr that referenced this pull request Oct 9, 2026
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 pushed a commit to mccode-dev/mccode-antlr that referenced this pull request Oct 9, 2026
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>

This branch has not been deployed

No deployments
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.

1 participant