Skip to content

Fix Python scratch-directory handling under parallel ctest - #3427

Merged
Lestropie merged 1 commit into
devfrom
ctest_python_scratch
Aug 4, 2026
Merged

Fix Python scratch-directory handling under parallel ctest#3427
Lestropie merged 1 commit into
devfrom
ctest_python_scratch

Conversation

@Lestropie

Copy link
Copy Markdown
Member

Extended #33424 in rectifying #3380.

For some Python command tests, the new ability of Python commands to utilise piped input / output images was used as justification to flag those tests with NO_FILESYSTEM_LOCK. This is however inappropriate: those commands will still typically generate a scratch directory, for which the default location is the current working directory, which will be wiped out by rm -rf *-tmp-*/ being executed by other tests in parallel. So the safest option is to just say that all Python tests require a filesystem lock and therefore cannot execute in parallel (technically some Python scripts don't need it as they don't create a scratch directory, but these are rare, and I don't think the maintenance burden is worthwhile).

Longer-term, a better solution might be for each test to create its own scratch directory, linking all contents of the test data directory so that the contents of the tests themselves don't need to be modified. That way any two tests could operate in parallel.

Some other fixes that Claude caught along the way:

  • Python piped images (and other temporaries) will go to the same location as C++ piped images do.
    Previously piped images were intended to go into the scratch directory of that command, but this apparently never worked as that scratch directory was always created after this decision was made.
  • mrtrix_cleanup tests were non-functional.

Python temporary-file naming now mirrors the C++ scheme. Piped image
data is no longer placed within a command's scratch directory, where
it risked being erased along with that directory before the receiving
command had read it. NO_FILESYSTEM_LOCK is no longer applied to any
Python command test, nor even parsed when registering them: every
Python command creates a scratch directory in the working directory,
which the wildcard cleanup of a concurrently-running test would wipe;
a single comment records that this divergence from the C++ tests is
deliberate. That wildcard removal of temporary content between tests
is retained, since failed Python tests would otherwise accumulate
scratch directories and bloat the filesystem. The mrtrix_cleanup
tests are repaired.

Prompts:
1. > In another Claude session, a flaw has been identified in recent augmentations of the parallel execution of tests in ctest. Most MRtrix3 Python commands will create a scratch directory to store intermediate data. This scratch directory is by default placed in the working directory (as some commands may exceed capacity of a RAM-backed /tmp filesystem). Its name is composed as "<cmdname>-tmp-??????", where "?" is a random alphanumeric. For tests that involve interaction with the filesystem, the working directory is wiped of any temporary content, including a wildcard that captures such paths. The issue encountered is that while some Python command tests have been flagged as NO_FILESYSTEM_LOCK due to not generating any derivative files or passing them down a pipe, they will still nevertheless create a scratch directory. So if another test is run in parallel that does involve filesystem access, that test may wipe the active scratch directory of a test that claims to not require filesystem use.
   > Possible rectifications:
   > 1. Do not mark any Python command tests that create a scratch directory as NO_FILESYSTEM_LOCK; safe, but precludes parallelism.
   > 2. Modify within the ctest execution process modification of the environment variable that sets the location of Python script scratch directories, so that they are created in a location that avoids the wildcard temporary deletion of other tests.
   > 3. Remove from the deletion of pre-existing temporary data from the test directory the wildcard that deletes Python command scratch directories.
   > Claude to generate any other plausible proposals.
   > Adjudicate candidate solutions and make recommendation based on consequences.
2. > Cleanup of *-tmp-* during testing is to remain in place: may have many failed Python command tests cause filesystem bloat.
   > 1. Fix utils.name_temporary() to mirror C++.
   > 2. Remove any attempt to place piped image data in the scratch directory. It would endanger erasure of the piped image when the scratch directory is deleted before the receiving command reads from it.
   > 3. Remove use of NO_FILESYSTEM_LOCK for any Python command. Do not even parse it in the cmake command that creates each test. Only leave behind one brief comment stating that its omission relative to C++ tests is deliberate based on scratch directory formation.
   > 4. Comment on whether Option 4 could parse the Bash test file, cross-referencing the test content with the content of the test data repository to discover the subset of symlinks that would need to be generated, and whether this would actually have any net benefit over creating a symlink for each and every item in the test data repository. Additionally comment on other candidate approaches for enabling parallel execution of tests, eg. modifying all tests to reference a data directory at a specified environment variable location, giving a unique name to every temporary output, et cetera. Bear in mind that some of the test suite design is carried over from a legacy bespoke design that did not conform to best practises.
   > 5. Fix the mrtrix_cleanup tests.

Generated-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lestropie Lestropie self-assigned this Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

clang-tidy review says "All clean, LGTM! 👍"

@Lestropie
Lestropie merged commit eb990b1 into dev Aug 4, 2026
7 checks passed
@Lestropie
Lestropie deleted the ctest_python_scratch branch August 4, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant