classification
Title: multiprocessing Arrays not automatically zeroed.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: jnoller, mark.dickinson, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2011-03-25 21:02 by mark.dickinson, last changed 2011-03-26 10:26 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
issue11675.patch mark.dickinson, 2011-03-25 21:33 review
Messages (7)
msg132153 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-25 21:02
The documentation for the multiprocessing module says:

"If size_or_initializer is an integer, then it determines the length of the array, and the array will be initially zeroed. "

But the part about the array being zeroed doesn't seem to be true:

Python 3.3a0 (default:03c7a83bbdd3, Mar 25 2011, 21:00:37) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from multiprocessing import Array
[67297 refs]
>>> arr1 = Array('i', [56, 27, 1729])
[79877 refs]
>>> del arr1
[79805 refs]
>>> arr2 = Array('i', 3)
[79876 refs]
>>> list(arr2)  # expect [0, 0, 0]
[56, 27, 1729]
[79882 refs]
msg132155 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-25 21:10
Since this behaviour seems to have been present since at least Python 2.6, it's tempting to call this a documentation bug.
msg132159 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-25 21:33
Here's a patch that adds zeroing.
msg132161 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-25 21:38
+1 for predictable behaviour and therefore zeroing of uninitialized arrays.
msg132165 - (view) Author: Jesse Noller (jnoller) * (Python committer) Date: 2011-03-25 22:00
I concur with Antoine. I think you're good to go Mark.
msg132222 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-26 10:02
New changeset 2af0c2c106ea by Mark Dickinson in branch '2.7':
Issue #11675:  Zero-out newly-created multiprocessing.[Raw]Array objects.
http://hg.python.org/cpython/rev/2af0c2c106ea
msg132225 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-26 10:23
New changeset 0cb276628528 by Mark Dickinson in branch '3.1':
Issue #11675:  Zero-out newly-created multiprocessing.[Raw]Array objects.
http://hg.python.org/cpython/rev/0cb276628528

New changeset 64ab52a64cc9 by Mark Dickinson in branch '3.2':
Merge #11675
http://hg.python.org/cpython/rev/64ab52a64cc9

New changeset f60e55b14d92 by Mark Dickinson in branch 'default':
Merge #11675
http://hg.python.org/cpython/rev/f60e55b14d92
History
Date User Action Args
2011-03-26 10:26:53mark.dickinsonsetstatus: open -> closed
assignee: mark.dickinson
resolution: fixed
stage: resolved
2011-03-26 10:23:34python-devsetmessages: + msg132225
2011-03-26 10:02:46python-devsetnosy: + python-dev
messages: + msg132222
2011-03-25 22:00:52jnollersetmessages: + msg132165
2011-03-25 21:38:30pitrousetnosy: + pitrou
messages: + msg132161
2011-03-25 21:33:38mark.dickinsonsetfiles: + issue11675.patch
keywords: + patch
messages: + msg132159
2011-03-25 21:10:51mark.dickinsonsetmessages: + msg132155
2011-03-25 21:02:04mark.dickinsoncreate