Skip to content

Commit bcff99c

Browse files
authored
gh-146202: Create tmp_dir in regrtest worker (#146347)
Create tmp_dir in libregrtest.worker since the directory can be different than the --tempdir directory.
1 parent 306c556 commit bcff99c

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
@@ -452,12 +452,6 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
452452
f"unexpectedly returned {tmp_dir!r} on WASI"
453453
)
454454
tmp_dir = os.path.join(tmp_dir, 'build')
455-
456-
# When get_temp_dir() is called in a worker process,
457-
# get_temp_dir() path is different than in the parent process
458-
# which is not a WASI process. So the parent does not create
459-
# the same "tmp_dir" than the test worker process.
460-
os.makedirs(tmp_dir, exist_ok=True)
461455
else:
462456
tmp_dir = tempfile.gettempdir()
463457

Lib/test/libregrtest/worker.py

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

129129
tmp_dir = get_temp_dir()
130+
# get_temp_dir() can be different in the worker and the parent process.
131+
# For example, if --tempdir option is used.
132+
os.makedirs(tmp_dir, exist_ok=True)
130133
work_dir = get_work_dir(tmp_dir, worker=True)
131134

132135
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)