Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87ea780

Browse files
committed
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.
1 parent 1074a92 commit 87ea780

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ Shared :mod:`ctypes` Objects
953953
It is possible to create shared objects using shared memory which can be
954954
inherited by child processes.
955955

956-
.. function:: Value(typecode_or_type, *args[, lock])
956+
.. function:: Value(typecode_or_type, *args, lock=True)
957957

958958
Return a :mod:`ctypes` object allocated from shared memory. By default the
959959
return value is actually a synchronized wrapper for the object.
@@ -1045,7 +1045,7 @@ processes.
10451045
attributes which allow one to use it to store and retrieve strings -- see
10461046
documentation for :mod:`ctypes`.
10471047

1048-
.. function:: Array(typecode_or_type, size_or_initializer, *args[, lock])
1048+
.. function:: Array(typecode_or_type, size_or_initializer, *, lock=True)
10491049

10501050
The same as :func:`RawArray` except that depending on the value of *lock* a
10511051
process-safe synchronization wrapper may be returned instead of a raw ctypes
@@ -1060,7 +1060,7 @@ processes.
10601060

10611061
Note that *lock* is a keyword-only argument.
10621062

1063-
.. function:: Value(typecode_or_type, *args[, lock])
1063+
.. function:: Value(typecode_or_type, *args, lock=True)
10641064

10651065
The same as :func:`RawValue` except that depending on the value of *lock* a
10661066
process-safe synchronization wrapper may be returned instead of a raw ctypes

Lib/multiprocessing/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,19 @@ def RawArray(typecode_or_type, size_or_initializer):
228228
from multiprocessing.sharedctypes import RawArray
229229
return RawArray(typecode_or_type, size_or_initializer)
230230

231-
def Value(typecode_or_type, *args, **kwds):
231+
def Value(typecode_or_type, *args, lock=True):
232232
'''
233233
Returns a synchronized shared object
234234
'''
235235
from multiprocessing.sharedctypes import Value
236-
return Value(typecode_or_type, *args, **kwds)
236+
return Value(typecode_or_type, *args, lock=lock)
237237

238-
def Array(typecode_or_type, size_or_initializer, **kwds):
238+
def Array(typecode_or_type, size_or_initializer, *, lock=True):
239239
'''
240240
Returns a synchronized shared array
241241
'''
242242
from multiprocessing.sharedctypes import Array
243-
return Array(typecode_or_type, size_or_initializer, **kwds)
243+
return Array(typecode_or_type, size_or_initializer, lock=lock)
244244

245245
#
246246
#

Lib/multiprocessing/sharedctypes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def RawArray(typecode_or_type, size_or_initializer):
6363
result.__init__(*size_or_initializer)
6464
return result
6565

66-
def Value(typecode_or_type, *args, lock=None):
66+
def Value(typecode_or_type, *args, lock=True):
6767
'''
6868
Return a synchronization wrapper for a Value
6969
'''
@@ -76,13 +76,10 @@ def Value(typecode_or_type, *args, lock=None):
7676
raise AttributeError("'%r' has no method 'acquire'" % lock)
7777
return synchronized(obj, lock)
7878

79-
def Array(typecode_or_type, size_or_initializer, **kwds):
79+
def Array(typecode_or_type, size_or_initializer, *, lock=True):
8080
'''
8181
Return a synchronization wrapper for a RawArray
8282
'''
83-
lock = kwds.pop('lock', None)
84-
if kwds:
85-
raise ValueError('unrecognized keyword argument(s): %s' % list(kwds.keys()))
8683
obj = RawArray(typecode_or_type, size_or_initializer)
8784
if lock is False:
8885
return obj

0 commit comments

Comments
 (0)