diff options
author | Raymond Hettinger <python@rcn.com> | 2013-03-04 07:58:40 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-03-04 07:58:40 (GMT) |
commit | 6c2078d545c5e0bcc5c393d30e670e8e4f9bb3e3 (patch) | |
tree | f5f469a4189ea19e930edf1365d507461c0f6dea /Lib/test/test_functools.py | |
parent | b6c65b2affec6bf194c26f8e94ed06420014efc0 (diff) | |
parent | 03923426733dcc9f6c998057114212c168c3b1cd (diff) | |
download | cpython-6c2078d545c5e0bcc5c393d30e670e8e4f9bb3e3.zip cpython-6c2078d545c5e0bcc5c393d30e670e8e4f9bb3e3.tar.gz cpython-6c2078d545c5e0bcc5c393d30e670e8e4f9bb3e3.tar.bz2 |
merge
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index fbf3ec4..9b3c31e 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -809,6 +809,31 @@ class TestLRU(unittest.TestCase): self.assertEqual(fib.cache_info(), 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): test_classes = ( TestPartialC, |