Skip to content

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

@Flamefire

Description

@Flamefire

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

if self.build_temp is None:
self.build_temp = os.path.join(self.build_base, 'temp' + plat_specifier)

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions