diff options
author | Charles-François Natali <neologix@free.fr> | 2011-07-02 12:35:49 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-07-02 12:35:49 (GMT) |
commit | 778db49da9eeb23af4410f592165d7e46d4a285a (patch) | |
tree | 13f82e6a6663d5af396bd723d01d2d4b57798a5c /Lib/test | |
parent | afa44a8096446bf1bad6c5d2acaac32a4b41b58d (diff) | |
download | cpython-778db49da9eeb23af4410f592165d7e46d4a285a.zip cpython-778db49da9eeb23af4410f592165d7e46d4a285a.tar.gz cpython-778db49da9eeb23af4410f592165d7e46d4a285a.tar.bz2 |
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.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 3e467d5..e9d0329 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1580,6 +1580,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, @@ -1597,6 +1599,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 + # # # |