changeset: 95595:0f944e424d67 user: Antoine Pitrou date: Mon Apr 13 20:53:43 2015 +0200 files: Lib/multiprocessing/heap.py Misc/ACKS Misc/NEWS description: 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. diff -r 53af5f557128 -r 0f944e424d67 Lib/multiprocessing/heap.py --- a/Lib/multiprocessing/heap.py Mon Apr 13 14:37:50 2015 -0400 +++ b/Lib/multiprocessing/heap.py Mon Apr 13 20:53:43 2015 +0200 @@ -71,7 +71,14 @@ 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): diff -r 53af5f557128 -r 0f944e424d67 Misc/ACKS --- a/Misc/ACKS Mon Apr 13 14:37:50 2015 -0400 +++ b/Misc/ACKS Mon Apr 13 20:53:43 2015 +0200 @@ -154,6 +154,7 @@ Gawain Bolton Forest Bond Gregory Bond +Médéric Boquien Matias Bordese Jonas Borgström Jurjen Bos diff -r 53af5f557128 -r 0f944e424d67 Misc/NEWS --- a/Misc/NEWS Mon Apr 13 14:37:50 2015 -0400 +++ b/Misc/NEWS Mon Apr 13 20:53:43 2015 +0200 @@ -29,6 +29,9 @@ Library ------- +- 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. + - Issue #22982: Improve BOM handling when seeking to multiple positions of a writable text file.