]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 68709 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sun, 18 Jan 2009 03:31:52 +0000 (03:31 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sun, 18 Jan 2009 03:31:52 +0000 (03:31 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r68709 | jesse.noller | 2009-01-17 21:11:38 -0600 (Sat, 17 Jan 2009) | 1 line

  Merge r68708 to py3k, fixes 4449
........

Doc/library/multiprocessing.rst
Lib/multiprocessing/sharedctypes.py
Lib/test/test_multiprocessing.py

index 9331b7cca76d434cb2af5f7338bd46a2c3852681..50714ef8826d285f28e4365e6cd59c3f887cfea4 100644 (file)
@@ -878,7 +878,7 @@ Shared :mod:`ctypes` Objects
 It is possible to create shared objects using shared memory which can be
 inherited by child processes.
 
-.. function:: Value(typecode_or_type[, *args, lock]])
+.. function:: Value(typecode_or_type, *args[, lock])
 
    Return a :mod:`ctypes` object allocated from shared memory.  By default the
    return value is actually a synchronized wrapper for the object.
@@ -960,7 +960,7 @@ processes.
 
    *typecode_or_type* determines the type of the returned object: it is either a
    ctypes type or a one character typecode of the kind used by the :mod:`array`
-   module.  */*args* is passed on to the constructor for the type.
+   module.  *\*args* is passed on to the constructor for the type.
 
    Note that setting and getting the value is potentially non-atomic -- use
    :func:`Value` instead to make sure that access is automatically synchronized
@@ -970,7 +970,7 @@ processes.
    attributes which allow one to use it to store and retrieve strings -- see
    documentation for :mod:`ctypes`.
 
-.. function:: Array(typecode_or_type, size_or_initializer[, *args[, lock]])
+.. function:: Array(typecode_or_type, size_or_initializer, *args[, lock])
 
    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
index b94cd52c9f12b7c4c4c4b9a3b153043017d7248c..1976277ad43717fa43dd3ac2d3f26ebc7d6857f0 100644 (file)
@@ -66,9 +66,12 @@ def Value(typecode_or_type, *args, lock=None):
     Return a synchronization wrapper for a Value
     '''
     obj = RawValue(typecode_or_type, *args)
-    if lock is None:
+    if lock is False:
+        return obj
+    if lock in (True, None):
         lock = RLock()
-    assert hasattr(lock, 'acquire')
+    if not hasattr(lock, 'acquire'):
+        raise AttributeError("'%r' has no method 'acquire'" % lock)
     return synchronized(obj, lock)
 
 def Array(typecode_or_type, size_or_initializer, **kwds):
@@ -79,9 +82,12 @@ 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 False:
+        return obj
+    if lock in (True, None):
         lock = RLock()
-    assert hasattr(lock, 'acquire')
+    if not hasattr(lock, 'acquire'):
+        raise AttributeError("'%r' has no method 'acquire'" % lock)
     return synchronized(obj, lock)
 
 def copy(obj):
index a8600c0fc74cd30e453a298337a93c03f1fb57ff..4e5d7597cbe3255b22f6ae04abc86eec39914b2b 100644 (file)
@@ -830,10 +830,16 @@ class _TestValue(BaseTestCase):
         obj3 = val3.get_obj()
         self.assertEqual(lock, lock3)
 
-        arr4 = self.RawValue('i', 5)
+        arr4 = self.Value('i', 5, lock=False)
         self.assertFalse(hasattr(arr4, 'get_lock'))
         self.assertFalse(hasattr(arr4, 'get_obj'))
 
+        self.assertRaises(AttributeError, self.Value, 'i', 5, lock='navalue')
+
+        arr5 = self.RawValue('i', 5)
+        self.assertFalse(hasattr(arr5, 'get_lock'))
+        self.assertFalse(hasattr(arr5, 'get_obj'))
+
 
 class _TestArray(BaseTestCase):
 
@@ -888,9 +894,15 @@ class _TestArray(BaseTestCase):
         obj3 = arr3.get_obj()
         self.assertEqual(lock, lock3)
 
-        arr4 = self.RawArray('i', list(range(10)))
+        arr4 = self.Array('i', range(10), lock=False)
         self.assertFalse(hasattr(arr4, 'get_lock'))
         self.assertFalse(hasattr(arr4, 'get_obj'))
+        self.assertRaises(AttributeError,
+                          self.Array, 'i', range(10), lock='notalock')
+
+        arr5 = self.RawArray('i', range(10))
+        self.assertFalse(hasattr(arr5, 'get_lock'))
+        self.assertFalse(hasattr(arr5, 'get_obj'))
 
 #
 #