summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-07-02 12:43:11 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-07-02 12:43:11 (GMT)
commit723585bbaf5a4c83d187c7868790cac5ac1991e9 (patch)
tree9084f9388ca9fb68b6a29b3637a53ee4835f1e3a /Lib/test
parent7ae4448ed235e37726d4082b75765fd6b4d0535a (diff)
parenta4a04069fd93395369b6061ed07f471e53f1c7a1 (diff)
downloadcpython-723585bbaf5a4c83d187c7868790cac5ac1991e9.zip
cpython-723585bbaf5a4c83d187c7868790cac5ac1991e9.tar.gz
cpython-723585bbaf5a4c83d187c7868790cac5ac1991e9.tar.bz2
Merge issue #12352: Fix a deadlock in multiprocessing.Heap when a block is
freed by the garbage collector while the Heap lock is held.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_multiprocessing.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index b752d8d..405fbd5 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -1721,6 +1721,8 @@ class _TestHeap(BaseTestCase):
# verify the state of the heap
all = []
occupied = 0
+ heap._lock.acquire()
+ self.addCleanup(heap._lock.release)
for L in list(heap._len_to_seq.values()):
for arena, start, stop in L:
all.append((heap._arenas.index(arena), start, stop,
@@ -1738,6 +1740,28 @@ class _TestHeap(BaseTestCase):
self.assertTrue((arena != narena and nstart == 0) or
(stop == nstart))
+ def test_free_from_gc(self):
+ # Check that freeing of blocks by the garbage collector doesn't deadlock
+ # (issue #12352).
+ # Make sure the GC is enabled, and set lower collection thresholds to
+ # make collections more frequent (and increase the probability of
+ # deadlock).
+ if not gc.isenabled():
+ gc.enable()
+ self.addCleanup(gc.disable)
+ thresholds = gc.get_threshold()
+ self.addCleanup(gc.set_threshold, *thresholds)
+ gc.set_threshold(10)
+
+ # perform numerous block allocations, with cyclic references to make
+ # sure objects are collected asynchronously by the gc
+ for i in range(5000):
+ a = multiprocessing.heap.BufferWrapper(1)
+ b = multiprocessing.heap.BufferWrapper(1)
+ # circular references
+ a.buddy = b
+ b.buddy = a
+
#
#
#