summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-04-13 18:53:43 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-04-13 18:53:43 (GMT)
commitd5aec7ba48c395db3386172b892e334bc55e44d3 (patch)
tree39c8ad485c6362a7e68615d886c36b6fc90958b3 /Lib/multiprocessing
parent4269d6db931d0a81b7d9b2705d97c48247c3448c (diff)
downloadcpython-d5aec7ba48c395db3386172b892e334bc55e44d3.zip
cpython-d5aec7ba48c395db3386172b892e334bc55e44d3.tar.gz
cpython-d5aec7ba48c395db3386172b892e334bc55e44d3.tar.bz2
Issue #21116: Avoid blowing memory when allocating a multiprocessing shared
array that's larger than 50% of the available RAM. Patch by Médéric Boquien.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/heap.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/multiprocessing/heap.py b/Lib/multiprocessing/heap.py
index 333b3ba..44d9638 100644
--- a/Lib/multiprocessing/heap.py
+++ b/Lib/multiprocessing/heap.py
@@ -71,7 +71,14 @@ else:
os.unlink(name)
util.Finalize(self, os.close, (self.fd,))
with open(self.fd, 'wb', closefd=False) as f:
- f.write(b'\0'*size)
+ bs = 1024 * 1024
+ if size >= bs:
+ zeros = b'\0' * bs
+ for _ in range(size // bs):
+ f.write(zeros)
+ del zeros
+ f.write(b'\0' * (size % bs))
+ assert f.tell() == size
self.buffer = mmap.mmap(self.fd, self.size)
def reduce_arena(a):