Skip to content

Commit f14bf53

Browse files
vstinnermiss-islington
authored andcommitted
gh-146202: Create tmp_dir in regrtest worker (GH-146347)
Create tmp_dir in libregrtest.worker since the directory can be different than the --tempdir directory. (cherry picked from commit bcff99c) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 43fe06b commit f14bf53

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Lib/test/libregrtest/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,6 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
466466
f"unexpectedly returned {tmp_dir!r} on WASI"
467467
)
468468
tmp_dir = os.path.join(tmp_dir, 'build')
469-
470-
# When get_temp_dir() is called in a worker process,
471-
# get_temp_dir() path is different than in the parent process
472-
# which is not a WASI process. So the parent does not create
473-
# the same "tmp_dir" than the test worker process.
474-
os.makedirs(tmp_dir, exist_ok=True)
475469
else:
476470
tmp_dir = tempfile.gettempdir()
477471

Lib/test/libregrtest/worker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def main() -> NoReturn:
112112
worker_json = sys.argv[1]
113113

114114
tmp_dir = get_temp_dir()
115+
# get_temp_dir() can be different in the worker and the parent process.
116+
# For example, if --tempdir option is used.
117+
os.makedirs(tmp_dir, exist_ok=True)
115118
work_dir = get_work_dir(tmp_dir, worker=True)
116119

117120
with exit_timeout():
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a race condition in regrtest: make sure that the temporary directory is
2+
created in the worker process. Previously, temp_cwd() could fail on Windows if
3+
the "build" directory was not created. Patch by Victor Stinner.

0 commit comments

Comments
 (0)