Skip to content

Remove only own temp folders in clean_tmpdir - #1296

Open
konstde00 wants to merge 1 commit into
sunlabuiuc:masterfrom
konstde00:cache-tmpdir-ownership
Open

konstde00 wants to merge 1 commit into
sunlabuiuc:masterfrom
konstde00:cache-tmpdir-ownership

Conversation

@konstde00

@konstde00 konstde00 commented Oct 14, 2026 •

Copy link
Copy Markdown

Contributor: Kostiantyn Dementiev (konstde00@gmail.com)
Contribution Type: Bug fix
Description: clean_tmpdir() removed the whole tmp/ folder, so a job could delete another job's temp folders on the same cache_dir. Now each dataset removes only the temp folders it created.
Files to Review:

  • pyhealth/datasets/base_dataset.py (__init__, create_tmpdir, clean_tmpdir)
  • tests/core/test_caching.py (TestTmpDirOwnership, 4 tests)
  • docs/api/datasets.rst
  • examples/dataset_cache_shared_tmpdir.py

Part of #1295.

create_tmpdir() records each folder it creates, and clean_tmpdir() removes only those, then tmp/ if it's empty. rmtree uses ignore_errors=True, because it runs in finally and a cleanup error should not hide the build's own error. The layout (tmp/<uuid>) is unchanged, so FHIRDataset and _proc_transform need no edits.

Behaviour change: folders left by killed jobs are no longer removed by another job's cleanup (question 3 in #1295).

Testing (macOS, Python 3.13.7): the 4 new tests pass (3 of them fail on master), the 30 existing cache tests pass, tools/check_pr_rules.py passes, and the full tests/core suite passes with both fixes from #1295 applied (1,525 OK, 96 skipped).

Currently clean_tmpdir() removes the whole cache_dir/tmp, so when one
job finishes a build, it deletes the temp folders of another job which
is still building on the same cache_dir.

Now each dataset keeps the list of temp folders it created and removes
only them, and tmp/ itself is removed only when it's empty. rmtree
uses ignore_errors=True, because it runs in finally blocks and a
cleanup error should not hide the build's own error.

Added 4 tests (TestTmpDirOwnership), a paragraph in
docs/api/datasets.rst and examples/dataset_cache_shared_tmpdir.py.

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