Skip to content

Commit b0516a6

Browse files
committed
Merge r68708 to py3k, fixes 4449
1 parent 34f9b4c commit b0516a6

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

Doc/library/multiprocessing.rst

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

881-
.. function:: Value(typecode_or_type[, *args, lock]])
881+
.. function:: Value(typecode_or_type, *args[, lock])
882882

883883
Return a :mod:`ctypes` object allocated from shared memory. By default the
884884
return value is actually a synchronized wrapper for the object.
@@ -960,7 +960,7 @@ processes.
960960

961961
*typecode_or_type* determines the type of the returned object: it is either a
962962
ctypes type or a one character typecode of the kind used by the :mod:`array`
963-
module. */*args* is passed on to the constructor for the type.
963+
module. *\*args* is passed on to the constructor for the type.
964964

965965
Note that setting and getting the value is potentially non-atomic -- use
966966
:func:`Value` instead to make sure that access is automatically synchronized
@@ -970,7 +970,7 @@ processes.
970970
attributes which allow one to use it to store and retrieve strings -- see
971971
documentation for :mod:`ctypes`.
972972

973-
.. function:: Array(typecode_or_type, size_or_initializer[, *args[, lock]])
973+
.. function:: Array(typecode_or_type, size_or_initializer, *args[, lock])
974974

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

Lib/multiprocessing/sharedctypes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ def Value(typecode_or_type, *args, lock=None):
6666
Return a synchronization wrapper for a Value
6767
'''
6868
obj = RawValue(typecode_or_type, *args)
69-
if lock is None:
69+
if lock is False:
70+
return obj
71+
if lock in (True, None):
7072
lock = RLock()
71-
assert hasattr(lock, 'acquire')
73+
if not hasattr(lock, 'acquire'):
74+
raise AttributeError("'%r' has no method 'acquire'" % lock)
7275
return synchronized(obj, lock)
7376

7477
def Array(typecode_or_type, size_or_initializer, **kwds):
@@ -79,9 +82,12 @@ def Array(typecode_or_type, size_or_initializer, **kwds):
7982
if kwds:
8083
raise ValueError('unrecognized keyword argument(s): %s' % list(kwds.keys()))
8184
obj = RawArray(typecode_or_type, size_or_initializer)
82-
if lock is None:
85+
if lock is False:
86+
return obj
87+
if lock in (True, None):
8388
lock = RLock()
84-
assert hasattr(lock, 'acquire')
89+
if not hasattr(lock, 'acquire'):
90+
raise AttributeError("'%r' has no method 'acquire'" % lock)
8591
return synchronized(obj, lock)
8692

8793
def copy(obj):

Lib/test/test_multiprocessing.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,16 @@ def test_getobj_getlock(self):
830830
obj3 = val3.get_obj()
831831
self.assertEqual(lock, lock3)
832832

833-
arr4 = self.RawValue('i', 5)
833+
arr4 = self.Value('i', 5, lock=False)
834834
self.assertFalse(hasattr(arr4, 'get_lock'))
835835
self.assertFalse(hasattr(arr4, 'get_obj'))
836836

837+
self.assertRaises(AttributeError, self.Value, 'i', 5, lock='navalue')
838+
839+
arr5 = self.RawValue('i', 5)
840+
self.assertFalse(hasattr(arr5, 'get_lock'))
841+
self.assertFalse(hasattr(arr5, 'get_obj'))
842+
837843

838844
class _TestArray(BaseTestCase):
839845

@@ -888,9 +894,15 @@ def test_getobj_getlock_obj(self):
888894
obj3 = arr3.get_obj()
889895
self.assertEqual(lock, lock3)
890896

891-
arr4 = self.RawArray('i', list(range(10)))
897+
arr4 = self.Array('i', range(10), lock=False)
892898
self.assertFalse(hasattr(arr4, 'get_lock'))
893899
self.assertFalse(hasattr(arr4, 'get_obj'))
900+
self.assertRaises(AttributeError,
901+
self.Array, 'i', range(10), lock='notalock')
902+
903+
arr5 = self.RawArray('i', range(10))
904+
self.assertFalse(hasattr(arr5, 'get_lock'))
905+
self.assertFalse(hasattr(arr5, 'get_obj'))
894906

895907
#
896908
#

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ Library
135135
- Issue #4959: inspect.formatargspec now works for keyword only arguments
136136
without defaults.
137137

138+
- Issue #4449: AssertionError in mp_benchmarks.py, caused by an underlying issue
139+
in sharedctypes.py.
140+
141+
- Issue #1225107: inspect.isclass() returned True for instances with a custom
142+
__getattr__.
143+
138144
- Issue #3826 and #4791: The socket module now closes the underlying socket
139145
appropriately when it is being used via socket.makefile() objects
140146
rather than delaying the close by waiting for garbage collection to do it.

0 commit comments

Comments
 (0)