]> granicus.if.org Git - python/commitdiff
Resolve issue 4449: AssertionError in mp_benchmarks.py
authorJesse Noller <jnoller@gmail.com>
Sun, 18 Jan 2009 02:45:38 +0000 (02:45 +0000)
committerJesse Noller <jnoller@gmail.com>
Sun, 18 Jan 2009 02:45:38 +0000 (02:45 +0000)
Doc/library/multiprocessing.rst
Lib/multiprocessing/sharedctypes.py
Lib/test/test_multiprocessing.py
Misc/NEWS

index 72ac38e92d4158c9b886adadc16719f682238ea0..fe54f9b2a78ff1600ec117aacdfc516b3aa5a529 100644 (file)
@@ -880,7 +880,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.
@@ -962,7 +962,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
@@ -972,7 +972,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 0054ff1822e5b7b824a6b3b20225bf203f052586..76b5e94b65bd3cf0140614beaa2ded9cbce0a9c1 100644 (file)
@@ -69,9 +69,12 @@ def Value(typecode_or_type, *args, **kwds):
     if kwds:
         raise ValueError('unrecognized keyword argument(s): %s' % kwds.keys())
     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):
@@ -82,9 +85,12 @@ def Array(typecode_or_type, size_or_initializer, **kwds):
     if kwds:
         raise ValueError('unrecognized keyword argument(s): %s' % 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 b0746e9f3b5dd9e6da3937e8ce4e678c9e93bfd7..2daff7edfdb2605689aa9a80ad9aabfdd1a1f964 100644 (file)
@@ -829,10 +829,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):
 
@@ -887,9 +893,15 @@ class _TestArray(BaseTestCase):
         obj3 = arr3.get_obj()
         self.assertEqual(lock, lock3)
 
-        arr4 = self.RawArray('i', 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'))
 
 #
 #
index 4c71db1eaf1c8c64a59107c3f9d372b5b4927ac5..f333a9238b92ad2f985a8150aa56fb521ad08257 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -137,6 +137,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #4449: AssertionError in mp_benchmarks.py, caused by an underlying issue
+  in sharedctypes.py.
+
 - Issue #1225107: inspect.isclass() returned True for instances with a custom
   __getattr__.