diff options
author | Jesse Noller <jnoller@gmail.com> | 2009-01-18 02:45:38 (GMT) |
---|---|---|
committer | Jesse Noller <jnoller@gmail.com> | 2009-01-18 02:45:38 (GMT) |
commit | 6ab22154ddabdb67bd510a1f2e0aa9c7e0ee607d (patch) | |
tree | 8e1d748c529dedc8fd67b9a1001673e898764465 /Lib | |
parent | b746448f46e2a996d4384ddc087eac31a60f318b (diff) | |
download | cpython-6ab22154ddabdb67bd510a1f2e0aa9c7e0ee607d.zip cpython-6ab22154ddabdb67bd510a1f2e0aa9c7e0ee607d.tar.gz cpython-6ab22154ddabdb67bd510a1f2e0aa9c7e0ee607d.tar.bz2 |
Resolve issue 4449: AssertionError in mp_benchmarks.py
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/multiprocessing/sharedctypes.py | 14 | ||||
-rw-r--r-- | Lib/test/test_multiprocessing.py | 16 |
2 files changed, 24 insertions, 6 deletions
diff --git a/Lib/multiprocessing/sharedctypes.py b/Lib/multiprocessing/sharedctypes.py index 0054ff1..76b5e94 100644 --- a/Lib/multiprocessing/sharedctypes.py +++ b/Lib/multiprocessing/sharedctypes.py @@ -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): diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index b0746e9..2daff7e 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -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')) # # |