pypa / pypa/setuptools

[BUG] Race condition due to reuse of build folder when building extensions in parallel

Open
#5,196 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

setuptools version

setuptools=70.0.0

Python version

Python 3.12

OS

RHEL 9

Additional environment information

No response

Description

Having multiple extensions in ext_modules being compiled in parallel with pip install --config-setting='--build-option=build_ext' --config-setting='--build-option=-j24' ... causes issues because they share the same build folder set at https://github.com/pypa/setuptools/blob/5a13876673a41e3cd21d4d6e587f53d0fb4fd8e5/setuptools/_distutils/command/build.py#L111-L112

So when they write anything into that folder they may overwrite or delete files used by other extensions

Expected behavior

Building extensions in parallel has the same result as building serially

How to Reproduce
  • Add multiple extensions to ext_modules that use e.g. the same source files but compile them e.g. with different flags.
  • Install with the parallel flag set

This was observed with DeepSpeed so you could try installing that from source with "enough" cores but it might be too much to setup

Output

Output varies and it might succeed depending on the amount of parallel actions going on and the available CPU cores. So it may sometimes succeed or fail seemingly randomly

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with setuptools/_distutils/command/build.py at the linked lines, then reproduce with multiple ext_modules that share source files but use different compilation flags and a parallel build. Compare parallel and serial results; done means parallel extension builds produce the same result without overwriting or deleting files used by another extension.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.