]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-146202: Create tmp_dir in regrtest worker (GH-146347) (#146349)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 24 Mar 2026 00:13:09 +0000 (01:13 +0100)
committerGitHub <noreply@github.com>
Tue, 24 Mar 2026 00:13:09 +0000 (00:13 +0000)
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 bcff99cb3f3b887a08c4f0ace1279ced38dd9e62)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/libregrtest/utils.py
Lib/test/libregrtest/worker.py
Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst [new file with mode: 0644]

index 58164d8a7983d59e6316b8c92743f8b555da5512..15caba75acfa3da0dd73981d274851f862e403a3 100644 (file)
@@ -433,12 +433,6 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
                         f"unexpectedly returned {tmp_dir!r} on WASI"
                     )
                 tmp_dir = os.path.join(tmp_dir, 'build')
-
-                # When get_temp_dir() is called in a worker process,
-                # get_temp_dir() path is different than in the parent process
-                # which is not a WASI process. So the parent does not create
-                # the same "tmp_dir" than the test worker process.
-                os.makedirs(tmp_dir, exist_ok=True)
         else:
             tmp_dir = tempfile.gettempdir()
 
index 1ad67e1cebf2881a3d85dfc5086d43cc5954a05e..4e69ab9d8fad05fe048df898d410d5112c101029 100644 (file)
@@ -127,6 +127,9 @@ def main() -> NoReturn:
     worker_json = sys.argv[1]
 
     tmp_dir = get_temp_dir()
+    # get_temp_dir() can be different in the worker and the parent process.
+    # For example, if --tempdir option is used.
+    os.makedirs(tmp_dir, exist_ok=True)
     work_dir = get_work_dir(tmp_dir, worker=True)
 
     with exit_timeout():
diff --git a/Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst b/Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst
new file mode 100644 (file)
index 0000000..ef869fe
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a race condition in regrtest: make sure that the temporary directory is
+created in the worker process. Previously, temp_cwd() could fail on Windows if
+the "build" directory was not created.  Patch by Victor Stinner.