New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiprocessing Array and sharedctypes.Array error in docs/implementation #47456
Comments
multiprocessing.sharedctypes.Array and Python 3.0b1+ (py3k:64518, Jun 25 2008, 12:52:38)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from multiprocessing import sharedctypes
>>> sharedctypes.Array('i', 1, lock=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
88, in Array
assert hasattr(lock, 'acquire')
AssertionError
>>> sharedctypes.Array('i', 1, lock=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
88, in Array
assert hasattr(lock, 'acquire')
AssertionError
>>> sharedctypes.Array('i', 1, lock=None)
<SynchronizedArray wrapper for
<multiprocessing.sharedctypes.c_long_Array_1 object at 0x83214f4>>
>>> Value('i', lock=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/multiprocessing/__init__.py", line 246,
in Value
return Value(typecode_or_type, *args, **kwds)
File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
75, in Value
assert hasattr(lock, 'acquire')
AssertionError The same goes for multiprocessing.Array and multiprocessing.Value. Comparing code to documentation it's obvious that lock argument can be |
And here is the patch itself. :) |
Note that if the error is in the documentation semantics, and not in the I'm not sure if the patch here is good or rather lock=True/False should diff --git a/Lib/multiprocessing/sharedctypes.py
b/Lib/multiprocessing/sharedctypes.py
index b94cd52..2f68e74 100644
--- a/Lib/multiprocessing/sharedctypes.py
+++ b/Lib/multiprocessing/sharedctypes.py
@@ -79,10 +79,11 @@ def Array(typecode_or_type, size_or_initializer,
**kwds):
if kwds:
raise ValueError('unrecognized keyword argument(s): %s' %
list(kwds.keys()))
obj = RawArray(typecode_or_type, size_or_initializer)
- if lock is None:
+ if lock is True:
lock = RLock()
- assert hasattr(lock, 'acquire')
- return synchronized(obj, lock)
+ return synchronized(obj, lock)
+ return obj
+
def copy(obj):
new_obj = _new_value(type(obj)) |
oops, there is a proper code patch in bpo-4449 , and the documentation |
Dupe, bpo-4449 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: