diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2014-05-25 13:12:12 (GMT) |
---|---|---|
committer | Charles-François Natali <cf.natali@gmail.com> | 2014-05-25 13:12:12 (GMT) |
commit | a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd (patch) | |
tree | cb29ab708c0a0c1f8ea51d20cdc7dbdd19a77046 /Lib/multiprocessing/heap.py | |
parent | 1691e35953858ae06b5198bf12c72a6cd0e0234b (diff) | |
download | cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.zip cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.tar.gz cpython-a924fc7abc2d8788a4a9fa2cbef2caa5c5992ebd.tar.bz2 |
Issue #21565: multiprocessing: use contex-manager protocol for synchronization
primitives.
Diffstat (limited to 'Lib/multiprocessing/heap.py')
-rw-r--r-- | Lib/multiprocessing/heap.py | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/Lib/multiprocessing/heap.py b/Lib/multiprocessing/heap.py index 344a45f..9e3016c 100644 --- a/Lib/multiprocessing/heap.py +++ b/Lib/multiprocessing/heap.py @@ -216,9 +216,8 @@ class Heap(object): assert 0 <= size < sys.maxsize if os.getpid() != self._lastpid: self.__init__() # reinitialize after fork - self._lock.acquire() - self._free_pending_blocks() - try: + with self._lock: + self._free_pending_blocks() size = self._roundup(max(size,1), self._alignment) (arena, start, stop) = self._malloc(size) new_stop = start + size @@ -227,8 +226,6 @@ class Heap(object): block = (arena, start, new_stop) self._allocated_blocks.add(block) return block - finally: - self._lock.release() # # Class representing a chunk of an mmap -- can be inherited by child process |