mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-139001: Fix thread-safety issue in pathlib.Path (gh-139066) (gh-139926)
Don't cache the joined path in `_raw_path` because the caching isn't thread safe.
(cherry picked from commit d9b4eef71e)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
7ea79f6342
commit
2660e98b30
3 changed files with 25 additions and 6 deletions
|
|
@ -3,6 +3,8 @@
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import threading
|
||||
from test.support import threading_helper
|
||||
|
||||
from .support import is_pypi
|
||||
from .support.lexical_path import LexicalPath
|
||||
|
|
@ -158,6 +160,26 @@ def test_parts(self):
|
|||
parts = p.parts
|
||||
self.assertEqual(parts, (sep, 'a', 'b'))
|
||||
|
||||
@threading_helper.requires_working_threading()
|
||||
def test_parts_multithreaded(self):
|
||||
P = self.cls
|
||||
|
||||
NUM_THREADS = 10
|
||||
NUM_ITERS = 10
|
||||
|
||||
for _ in range(NUM_ITERS):
|
||||
b = threading.Barrier(NUM_THREADS)
|
||||
path = P('a') / 'b' / 'c' / 'd' / 'e'
|
||||
expected = ('a', 'b', 'c', 'd', 'e')
|
||||
|
||||
def check_parts():
|
||||
b.wait()
|
||||
self.assertEqual(path.parts, expected)
|
||||
|
||||
threads = [threading.Thread(target=check_parts) for _ in range(NUM_THREADS)]
|
||||
with threading_helper.start_threads(threads):
|
||||
pass
|
||||
|
||||
def test_parent(self):
|
||||
# Relative
|
||||
P = self.cls
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue