Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-93584: Avoid file race condition in build process #93586

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/_bootsubprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
subprocess is unavailable. setup.py is not used on Windows.
"""
import os
import time


# distutils.spawn used by distutils.command.build_ext
Expand Down Expand Up @@ -70,7 +71,9 @@ def check_output(cmd, **kwargs):
if not _check_cmd(cmd):
raise ValueError(f"unsupported command: {cmd!r}")

tmp_filename = "check_output.tmp"
# include pid and time stamp to avoid file name clashes with parallel
# builds.
tmp_filename = f"check_output-{os.getpid()}-{int(time.time() )}.tmp"
if not isinstance(cmd, str):
cmd = " ".join(cmd)
cmd = f"{cmd} >{tmp_filename}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid file race condition in ``setup.py`` ``add_multiarch_paths()`` method
and ``_bootsubprocess.check_output()`` function.
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shlex
import sys
import sysconfig
import time
import warnings
from glob import glob, escape
import _osx_support
Expand Down Expand Up @@ -688,9 +689,15 @@ def check_extension_import(self, ext):
def add_multiarch_paths(self):
# Debian/Ubuntu multiarch support.
# https://wiki.ubuntu.com/MultiarchSpec
tmpfile = os.path.join(self.build_temp, 'multiarch')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)

# Poor man's conflict avoidance. PGO build use $(MAKE), which runs
# make in a separate, untracked process. Sometimes main and subproces
# run `make sharedmods` at the same time. One process removes
# "multiarch" file of the other process.
tmpfile = os.path.join(
self.build_temp, f"multiarch-{os.getpid()}-{int(time.time() )}.tmp"
)
os.makedirs(self.build_temp, exist_ok=True)
ret = run_command(
'%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile))
multiarch_path_component = ''
Expand All @@ -713,9 +720,7 @@ def add_multiarch_paths(self):
opt = ''
if CROSS_COMPILING:
opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
tmpfile = os.path.join(self.build_temp, 'multiarch')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
os.makedirs(self.build_temp, exist_ok=True)
ret = run_command(
'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
(opt, tmpfile))
Expand Down