diff options
author | Charles-François Natali <neologix@free.fr> | 2011-07-02 13:56:19 +0200 |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-07-02 13:56:19 +0200 |
commit | 414d0faedced1b7cb3585e76e0bdfff1795e15f3 (patch) | |
tree | 8ed8c8cc1debe19c9542cd063b514e9b4f3e6d17 /Lib/test/test_multiprocessing.py | |
parent | ff48c0a89b501df92c78873352956348d5cb0690 (diff) | |
download | cpython-git-414d0faedced1b7cb3585e76e0bdfff1795e15f3.tar.gz |
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/test_multiprocessing.py')
-rw-r--r-- | Lib/test/test_multiprocessing.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index de5e46a1e4..18a2f29f0a 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1615,6 +1615,8 @@ class _TestHeap(BaseTestCase): # verify the state of the heap all = [] occupied = 0 + heap._lock.acquire() + self.addCleanup(heap._lock.release) for L in heap._len_to_seq.values(): for arena, start, stop in L: all.append((heap._arenas.index(arena), start, stop, @@ -1632,6 +1634,29 @@ 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 gc.isenabled(): + thresholds = gc.get_threshold() + self.addCleanup(gc.set_threshold, *thresholds) + else: + gc.enable() + self.addCleanup(gc.disable) + 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 + # # # |