MCPcopy Index your code
hub / github.com/python/cpython / test_need_for_rlock

Method test_need_for_rlock

Lib/test/test_functools.py:2041–2063  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2039 pass
2040
2041 def test_need_for_rlock(self):
2042 # This will deadlock on an LRU cache that uses a regular lock
2043
2044 @self.module.lru_cache(maxsize=10)
2045 def test_func(x):
2046 'Used to demonstrate a reentrant lru_cache call within a single thread'
2047 return x
2048
2049 class DoubleEq:
2050 'Demonstrate a reentrant lru_cache call within a single thread'
2051 def __init__(self, x):
2052 self.x = x
2053 def __hash__(self):
2054 return self.x
2055 def __eq__(self, other):
2056 if self.x == 2:
2057 test_func(DoubleEq(1))
2058 return self.x == other.x
2059
2060 test_func(DoubleEq(1)) # Load the cache
2061 test_func(DoubleEq(2)) # Load the cache
2062 self.assertEqual(test_func(DoubleEq(2)), # Trigger a re-entrant __eq__ call
2063 DoubleEq(2)) # Verify the correct return value
2064
2065 def test_lru_method(self):
2066 class X(int):

Callers

nothing calls this directly

Calls 3

DoubleEqClass · 0.85
test_funcClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected