Commit 87ea780e authored by Richard Oudkerk's avatar Richard Oudkerk

Use Python 3.x-style keyword only arg in Array()

Previously a Python 2.x compatible hack was used for
multiprocessing.sharedctypes.Array().  Also the documented
signature was wrong.
parent 1074a929
...@@ -953,7 +953,7 @@ Shared :mod:`ctypes` Objects ...@@ -953,7 +953,7 @@ Shared :mod:`ctypes` Objects
It is possible to create shared objects using shared memory which can be It is possible to create shared objects using shared memory which can be
inherited by child processes. inherited by child processes.
.. function:: Value(typecode_or_type, *args[, lock]) .. function:: Value(typecode_or_type, *args, lock=True)
Return a :mod:`ctypes` object allocated from shared memory. By default the Return a :mod:`ctypes` object allocated from shared memory. By default the
return value is actually a synchronized wrapper for the object. return value is actually a synchronized wrapper for the object.
...@@ -1045,7 +1045,7 @@ processes. ...@@ -1045,7 +1045,7 @@ processes.
attributes which allow one to use it to store and retrieve strings -- see attributes which allow one to use it to store and retrieve strings -- see
documentation for :mod:`ctypes`. documentation for :mod:`ctypes`.
.. function:: Array(typecode_or_type, size_or_initializer, *args[, lock]) .. function:: Array(typecode_or_type, size_or_initializer, *, lock=True)
The same as :func:`RawArray` except that depending on the value of *lock* a The same as :func:`RawArray` except that depending on the value of *lock* a
process-safe synchronization wrapper may be returned instead of a raw ctypes process-safe synchronization wrapper may be returned instead of a raw ctypes
...@@ -1060,7 +1060,7 @@ processes. ...@@ -1060,7 +1060,7 @@ processes.
Note that *lock* is a keyword-only argument. Note that *lock* is a keyword-only argument.
.. function:: Value(typecode_or_type, *args[, lock]) .. function:: Value(typecode_or_type, *args, lock=True)
The same as :func:`RawValue` except that depending on the value of *lock* a The same as :func:`RawValue` except that depending on the value of *lock* a
process-safe synchronization wrapper may be returned instead of a raw ctypes process-safe synchronization wrapper may be returned instead of a raw ctypes
......
...@@ -228,19 +228,19 @@ def RawArray(typecode_or_type, size_or_initializer): ...@@ -228,19 +228,19 @@ def RawArray(typecode_or_type, size_or_initializer):
from multiprocessing.sharedctypes import RawArray from multiprocessing.sharedctypes import RawArray
return RawArray(typecode_or_type, size_or_initializer) return RawArray(typecode_or_type, size_or_initializer)
def Value(typecode_or_type, *args, **kwds): def Value(typecode_or_type, *args, lock=True):
''' '''
Returns a synchronized shared object Returns a synchronized shared object
''' '''
from multiprocessing.sharedctypes import Value from multiprocessing.sharedctypes import Value
return Value(typecode_or_type, *args, **kwds) return Value(typecode_or_type, *args, lock=lock)
def Array(typecode_or_type, size_or_initializer, **kwds): def Array(typecode_or_type, size_or_initializer, *, lock=True):
''' '''
Returns a synchronized shared array Returns a synchronized shared array
''' '''
from multiprocessing.sharedctypes import Array from multiprocessing.sharedctypes import Array
return Array(typecode_or_type, size_or_initializer, **kwds) return Array(typecode_or_type, size_or_initializer, lock=lock)
# #
# #
......
...@@ -63,7 +63,7 @@ def RawArray(typecode_or_type, size_or_initializer): ...@@ -63,7 +63,7 @@ def RawArray(typecode_or_type, size_or_initializer):
result.__init__(*size_or_initializer) result.__init__(*size_or_initializer)
return result return result
def Value(typecode_or_type, *args, lock=None): def Value(typecode_or_type, *args, lock=True):
''' '''
Return a synchronization wrapper for a Value Return a synchronization wrapper for a Value
''' '''
...@@ -76,13 +76,10 @@ def Value(typecode_or_type, *args, lock=None): ...@@ -76,13 +76,10 @@ def Value(typecode_or_type, *args, lock=None):
raise AttributeError("'%r' has no method 'acquire'" % lock) raise AttributeError("'%r' has no method 'acquire'" % lock)
return synchronized(obj, lock) return synchronized(obj, lock)
def Array(typecode_or_type, size_or_initializer, **kwds): def Array(typecode_or_type, size_or_initializer, *, lock=True):
''' '''
Return a synchronization wrapper for a RawArray Return a synchronization wrapper for a RawArray
''' '''
lock = kwds.pop('lock', None)
if kwds:
raise ValueError('unrecognized keyword argument(s): %s' % list(kwds.keys()))
obj = RawArray(typecode_or_type, size_or_initializer) obj = RawArray(typecode_or_type, size_or_initializer)
if lock is False: if lock is False:
return obj return obj
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment