]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-38807: Fix race condition in Lib/trace.py (GH-110143)
authorbuermarc <44375277+buermarc@users.noreply.github.com>
Wed, 17 Jan 2024 20:02:14 +0000 (21:02 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2024 20:02:14 +0000 (22:02 +0200)
Instead of checking if a directory does not exist and thereafter
creating it, directly call os.makedirs() with the exist_ok=True.

Lib/trace.py
Misc/NEWS.d/next/Library/2023-09-22-22-17-45.gh-issue-38807.m9McRN.rst [new file with mode: 0644]

index 7cb6f897634b14e71ff3331970fba3e00af4dbb9..7886959fa64f68422f8c26e62064e7f661b347ec 100755 (executable)
@@ -265,8 +265,7 @@ class CoverageResults:
                 modulename = _modname(filename)
             else:
                 dir = coverdir
-                if not os.path.exists(dir):
-                    os.makedirs(dir)
+                os.makedirs(dir, exist_ok=True)
                 modulename = _fullmodname(filename)
 
             # If desired, get a list of the line numbers which represent
diff --git a/Misc/NEWS.d/next/Library/2023-09-22-22-17-45.gh-issue-38807.m9McRN.rst b/Misc/NEWS.d/next/Library/2023-09-22-22-17-45.gh-issue-38807.m9McRN.rst
new file mode 100644 (file)
index 0000000..4219723
--- /dev/null
@@ -0,0 +1,3 @@
+Fix race condition in :mod:`trace`. Instead of checking if a directory
+exists and creating it, directly call :func:`os.makedirs` with the kwarg
+``exist_ok=True``.