Skip to content

Commit 2dca689

Browse files
[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 78fcde0) Co-authored-by: buermarc <[email protected]>
1 parent 2b03259 commit 2dca689

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/trace.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
258258
modulename = _modname(filename)
259259
else:
260260
dir = coverdir
261-
if not os.path.exists(dir):
262-
os.makedirs(dir)
261+
os.makedirs(dir, exist_ok=True)
263262
modulename = _fullmodname(filename)
264263

265264
# If desired, get a list of the line numbers which represent
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix race condition in :mod:`trace`. Instead of checking if a directory
2+
exists and creating it, directly call :func:`os.makedirs` with the kwarg
3+
``exist_ok=True``.

0 commit comments

Comments
 (0)