https://github.com/python/cpython/commit/2dca68935e4884216822d18debcbf9a8e252dc21
commit: 2dca68935e4884216822d18debcbf9a8e252dc21
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-01-17T20:26:09Z
summary:

[3.11] gh-38807: Fix race condition in Lib/trace.py (GH-110143) (GH-114207)

Instead of checking if a directory does not exist and thereafter
creating it, directly call os.makedirs() with the exist_ok=True.
(cherry picked from commit 78fcde039a33d8463e34356d5462fecee0f2831a)

Co-authored-by: buermarc <[email protected]>

files:
A Misc/NEWS.d/next/Library/2023-09-22-22-17-45.gh-issue-38807.m9McRN.rst
M Lib/trace.py

diff --git a/Lib/trace.py b/Lib/trace.py
index fb9a423ea09fce..761916b18097d6 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -258,8 +258,7 @@ def write_results(self, show_missing=True, summary=False, 
coverdir=None):
                 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
index 00000000000000..4219723d15b9e6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-09-22-22-17-45.gh-issue-38807.m9McRN.rst
@@ -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``.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to