[Python-checkins] cpython (merge 3.3 -> default): merge
raymond.hettinger
python-checkins at python.org
Mon Mar 4 08:59:01 CET 2013
http://hg.python.org/cpython/rev/af1961e38ccb
changeset: 82467:af1961e38ccb
parent: 82465:362826298fdb
parent: 82466:f27eaeffc4c0
user: Raymond Hettinger <python at rcn.com>
date: Mon Mar 04 02:58:40 2013 -0500
summary:
merge
files:
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
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -809,6 +809,31 @@
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,
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list