Skip to content

Commit 1f6e77f

Browse files
committed
gh-139001: Fix thread-safety issue in pathlib.Path
Don't cache the joined path in `_raw_path` because the caching isn't thread safe.
1 parent 8eb1062 commit 1f6e77f

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Lib/pathlib/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,8 @@ def _raw_path(self):
335335
return paths[0]
336336
elif paths:
337337
# Join path segments from the initializer.
338-
path = self.parser.join(*paths)
339-
# Cache the joined path.
340-
paths.clear()
341-
paths.append(path)
342-
return path
338+
return self.parser.join(*paths)
343339
else:
344-
paths.append('')
345340
return ''
346341

347342
@property
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix race condition in :class:`pathlib.Path` on the internal ``_raw_paths``
2+
field.

0 commit comments

Comments
 (0)