Skip to content

Commit 78fcde0

Browse files
authored
gh-38807: Fix race condition in Lib/trace.py (GH-110143)
Instead of checking if a directory does not exist and thereafter creating it, directly call os.makedirs() with the exist_ok=True.
1 parent 7573c44 commit 78fcde0

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
@@ -265,8 +265,7 @@ def write_results(self, show_missing=True, summary=False, coverdir=None, *,
265265
modulename = _modname(filename)
266266
else:
267267
dir = coverdir
268-
if not os.path.exists(dir):
269-
os.makedirs(dir)
268+
os.makedirs(dir, exist_ok=True)
270269
modulename = _fullmodname(filename)
271270

272271
# 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)