Skip to content

Commit e11c5e1

Browse files
committed
gh-38807: fix race condition in Lib/trace.py
Instead of checking if a directory does not exist and thereafter creating it, directly call `os.makedirs` with the `exist_ok` kwarg.
1 parent 0449fe9 commit e11c5e1

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)