mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
merge
This commit is contained in:
commit
6c2078d545
1 changed files with 25 additions and 0 deletions
|
@ -809,6 +809,31 @@ class TestLRU(unittest.TestCase):
|
||||||
self.assertEqual(fib.cache_info(),
|
self.assertEqual(fib.cache_info(),
|
||||||
functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0))
|
functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0))
|
||||||
|
|
||||||
|
def test_need_for_rlock(self):
|
||||||
|
# This will deadlock on an LRU cache that uses a regular lock
|
||||||
|
|
||||||
|
@functools.lru_cache(maxsize=10)
|
||||||
|
def test_func(x):
|
||||||
|
'Used to demonstrate a reentrant lru_cache call within a single thread'
|
||||||
|
return x
|
||||||
|
|
||||||
|
class DoubleEq:
|
||||||
|
'Demonstrate a reentrant lru_cache call within a single thread'
|
||||||
|
def __init__(self, x):
|
||||||
|
self.x = x
|
||||||
|
def __hash__(self):
|
||||||
|
return self.x
|
||||||
|
def __eq__(self, other):
|
||||||
|
if self.x == 2:
|
||||||
|
test_func(DoubleEq(1))
|
||||||
|
return self.x == other.x
|
||||||
|
|
||||||
|
test_func(DoubleEq(1)) # Load the cache
|
||||||
|
test_func(DoubleEq(2)) # Load the cache
|
||||||
|
self.assertEqual(test_func(DoubleEq(2)), # Trigger a re-entrant __eq__ call
|
||||||
|
DoubleEq(2)) # Verify the correct return value
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
test_classes = (
|
test_classes = (
|
||||||
TestPartialC,
|
TestPartialC,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue