mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-87634: remove locking from functools.cached_property (GH-101890)
Remove the undocumented locking capabilities of functools.cached_property.
This commit is contained in:
parent
8f647477f0
commit
056dfc71dc
5 changed files with 35 additions and 54 deletions
|
@ -2931,21 +2931,6 @@ class OptionallyCachedCostItem:
|
|||
cached_cost = py_functools.cached_property(get_cost)
|
||||
|
||||
|
||||
class CachedCostItemWait:
|
||||
|
||||
def __init__(self, event):
|
||||
self._cost = 1
|
||||
self.lock = py_functools.RLock()
|
||||
self.event = event
|
||||
|
||||
@py_functools.cached_property
|
||||
def cost(self):
|
||||
self.event.wait(1)
|
||||
with self.lock:
|
||||
self._cost += 1
|
||||
return self._cost
|
||||
|
||||
|
||||
class CachedCostItemWithSlots:
|
||||
__slots__ = ('_cost')
|
||||
|
||||
|
@ -2970,27 +2955,6 @@ class TestCachedProperty(unittest.TestCase):
|
|||
self.assertEqual(item.get_cost(), 4)
|
||||
self.assertEqual(item.cached_cost, 3)
|
||||
|
||||
@threading_helper.requires_working_threading()
|
||||
def test_threaded(self):
|
||||
go = threading.Event()
|
||||
item = CachedCostItemWait(go)
|
||||
|
||||
num_threads = 3
|
||||
|
||||
orig_si = sys.getswitchinterval()
|
||||
sys.setswitchinterval(1e-6)
|
||||
try:
|
||||
threads = [
|
||||
threading.Thread(target=lambda: item.cost)
|
||||
for k in range(num_threads)
|
||||
]
|
||||
with threading_helper.start_threads(threads):
|
||||
go.set()
|
||||
finally:
|
||||
sys.setswitchinterval(orig_si)
|
||||
|
||||
self.assertEqual(item.cost, 2)
|
||||
|
||||
def test_object_with_slots(self):
|
||||
item = CachedCostItemWithSlots()
|
||||
with self.assertRaisesRegex(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue