[Python-checkins] r86131 - in python/branches/release27-maint: Lib/test/test_multiprocessing.py

antoine.pitrou python-checkins at python.org
Wed Nov 3 00:51:30 CET 2010


Author: antoine.pitrou
Date: Wed Nov  3 00:51:30 2010
New Revision: 86131

Log:
Merged revisions 86130 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86130 | antoine.pitrou | 2010-11-03 00:50:11 +0100 (mer., 03 nov. 2010) | 3 lines
  
  Issue #10173: test_multiprocessing shouldn't pickle TestCase instances
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/test/test_multiprocessing.py

Modified: python/branches/release27-maint/Lib/test/test_multiprocessing.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_multiprocessing.py	(original)
+++ python/branches/release27-maint/Lib/test/test_multiprocessing.py	Wed Nov  3 00:51:30 2010
@@ -115,6 +115,13 @@
         else:
             return self.assertEqual(value, res)
 
+    # For the sanity of Windows users, rather than crashing or freezing in
+    # multiple ways.
+    def __reduce__(self, *args):
+        raise NotImplementedError("shouldn't try to pickle a test case")
+
+    __reduce_ex__ = __reduce__
+
 #
 # Return the value of a semaphore
 #
@@ -153,12 +160,13 @@
         self.assertEqual(current.ident, os.getpid())
         self.assertEqual(current.exitcode, None)
 
-    def _test(self, q, *args, **kwds):
-        current = self.current_process()
+    @classmethod
+    def _test(cls, q, *args, **kwds):
+        current = cls.current_process()
         q.put(args)
         q.put(kwds)
         q.put(current.name)
-        if self.TYPE != 'threads':
+        if cls.TYPE != 'threads':
             q.put(bytes(current.authkey))
             q.put(current.pid)
 
@@ -201,7 +209,8 @@
         self.assertEquals(p.is_alive(), False)
         self.assertNotIn(p, self.active_children())
 
-    def _test_terminate(self):
+    @classmethod
+    def _test_terminate(cls):
         time.sleep(1000)
 
     def test_terminate(self):
@@ -250,13 +259,14 @@
         p.join()
         self.assertNotIn(p, self.active_children())
 
-    def _test_recursion(self, wconn, id):
+    @classmethod
+    def _test_recursion(cls, wconn, id):
         from multiprocessing import forking
         wconn.send(id)
         if len(id) < 2:
             for i in range(2):
-                p = self.Process(
-                    target=self._test_recursion, args=(wconn, id+[i])
+                p = cls.Process(
+                    target=cls._test_recursion, args=(wconn, id+[i])
                     )
                 p.start()
                 p.join()
@@ -339,7 +349,8 @@
 class _TestQueue(BaseTestCase):
 
 
-    def _test_put(self, queue, child_can_start, parent_can_continue):
+    @classmethod
+    def _test_put(cls, queue, child_can_start, parent_can_continue):
         child_can_start.wait()
         for i in range(6):
             queue.get()
@@ -403,7 +414,8 @@
 
         proc.join()
 
-    def _test_get(self, queue, child_can_start, parent_can_continue):
+    @classmethod
+    def _test_get(cls, queue, child_can_start, parent_can_continue):
         child_can_start.wait()
         #queue.put(1)
         queue.put(2)
@@ -464,7 +476,8 @@
 
         proc.join()
 
-    def _test_fork(self, queue):
+    @classmethod
+    def _test_fork(cls, queue):
         for i in range(10, 20):
             queue.put(i)
         # note that at this point the items may only be buffered, so the
@@ -512,7 +525,8 @@
         q.get()
         self.assertEqual(q.qsize(), 0)
 
-    def _test_task_done(self, q):
+    @classmethod
+    def _test_task_done(cls, q):
         for obj in iter(q.get, None):
             time.sleep(DELTA)
             q.task_done()
@@ -624,7 +638,8 @@
 
 class _TestCondition(BaseTestCase):
 
-    def f(self, cond, sleeping, woken, timeout=None):
+    @classmethod
+    def f(cls, cond, sleeping, woken, timeout=None):
         cond.acquire()
         sleeping.release()
         cond.wait(timeout)
@@ -756,7 +771,8 @@
 
 class _TestEvent(BaseTestCase):
 
-    def _test_event(self, event):
+    @classmethod
+    def _test_event(cls, event):
         time.sleep(TIMEOUT2)
         event.set()
 
@@ -809,8 +825,9 @@
         ('c', latin('x'), latin('y'))
         ]
 
-    def _test(self, values):
-        for sv, cv in zip(values, self.codes_values):
+    @classmethod
+    def _test(cls, values):
+        for sv, cv in zip(values, cls.codes_values):
             sv.value = cv[2]
 
 
@@ -865,7 +882,8 @@
 
     ALLOWED_TYPES = ('processes',)
 
-    def f(self, seq):
+    @classmethod
+    def f(cls, seq):
         for i in range(1, len(seq)):
             seq[i] += seq[i-1]
 
@@ -1210,7 +1228,8 @@
 
     ALLOWED_TYPES = ('manager',)
 
-    def _putter(self, address, authkey):
+    @classmethod
+    def _putter(cls, address, authkey):
         manager = QueueManager2(
             address=address, authkey=authkey, serializer=SERIALIZER
             )
@@ -1248,7 +1267,8 @@
 
 class _TestManagerRestart(BaseTestCase):
 
-    def _putter(self, address, authkey):
+    @classmethod
+    def _putter(cls, address, authkey):
         manager = QueueManager(
             address=address, authkey=authkey, serializer=SERIALIZER)
         manager.connect()
@@ -1287,7 +1307,8 @@
 
     ALLOWED_TYPES = ('processes', 'threads')
 
-    def _echo(self, conn):
+    @classmethod
+    def _echo(cls, conn):
         for msg in iter(conn.recv_bytes, SENTINEL):
             conn.send_bytes(msg)
         conn.close()
@@ -1436,8 +1457,9 @@
 
     ALLOWED_TYPES = ('processes', 'threads')
 
-    def _test(self, address):
-        conn = self.connection.Client(address)
+    @classmethod
+    def _test(cls, address):
+        conn = cls.connection.Client(address)
         conn.send('hello')
         conn.close()
 
@@ -1598,7 +1620,8 @@
 
     ALLOWED_TYPES = ('processes',)
 
-    def _double(self, x, y, foo, arr, string):
+    @classmethod
+    def _double(cls, x, y, foo, arr, string):
         x.value *= 2
         y.value *= 2
         foo.x *= 2
@@ -1646,7 +1669,8 @@
 
     ALLOWED_TYPES = ('processes',)
 
-    def _test_finalize(self, conn):
+    @classmethod
+    def _test_finalize(cls, conn):
         class Foo(object):
             pass
 
@@ -1740,7 +1764,8 @@
         logger.info('nor will this')
         logger.setLevel(LOG_LEVEL)
 
-    def _test_level(self, conn):
+    @classmethod
+    def _test_level(cls, conn):
         logger = multiprocessing.get_logger()
         conn.send(logger.getEffectiveLevel())
 


More information about the Python-checkins mailing list