mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #10173: test_multiprocessing shouldn't pickle TestCase instances
This commit is contained in:
parent
f80b3f72c6
commit
0d1b38cef9
1 changed files with 49 additions and 24 deletions
|
@ -118,6 +118,13 @@ class BaseTestCase(object):
|
||||||
else:
|
else:
|
||||||
return self.assertEqual(value, res)
|
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
|
# Return the value of a semaphore
|
||||||
#
|
#
|
||||||
|
@ -156,12 +163,13 @@ class _TestProcess(BaseTestCase):
|
||||||
self.assertEqual(current.ident, os.getpid())
|
self.assertEqual(current.ident, os.getpid())
|
||||||
self.assertEqual(current.exitcode, None)
|
self.assertEqual(current.exitcode, None)
|
||||||
|
|
||||||
def _test(self, q, *args, **kwds):
|
@classmethod
|
||||||
current = self.current_process()
|
def _test(cls, q, *args, **kwds):
|
||||||
|
current = cls.current_process()
|
||||||
q.put(args)
|
q.put(args)
|
||||||
q.put(kwds)
|
q.put(kwds)
|
||||||
q.put(current.name)
|
q.put(current.name)
|
||||||
if self.TYPE != 'threads':
|
if cls.TYPE != 'threads':
|
||||||
q.put(bytes(current.authkey))
|
q.put(bytes(current.authkey))
|
||||||
q.put(current.pid)
|
q.put(current.pid)
|
||||||
|
|
||||||
|
@ -204,7 +212,8 @@ class _TestProcess(BaseTestCase):
|
||||||
self.assertEquals(p.is_alive(), False)
|
self.assertEquals(p.is_alive(), False)
|
||||||
self.assertNotIn(p, self.active_children())
|
self.assertNotIn(p, self.active_children())
|
||||||
|
|
||||||
def _test_terminate(self):
|
@classmethod
|
||||||
|
def _test_terminate(cls):
|
||||||
time.sleep(1000)
|
time.sleep(1000)
|
||||||
|
|
||||||
def test_terminate(self):
|
def test_terminate(self):
|
||||||
|
@ -253,13 +262,14 @@ class _TestProcess(BaseTestCase):
|
||||||
p.join()
|
p.join()
|
||||||
self.assertNotIn(p, self.active_children())
|
self.assertNotIn(p, self.active_children())
|
||||||
|
|
||||||
def _test_recursion(self, wconn, id):
|
@classmethod
|
||||||
|
def _test_recursion(cls, wconn, id):
|
||||||
from multiprocessing import forking
|
from multiprocessing import forking
|
||||||
wconn.send(id)
|
wconn.send(id)
|
||||||
if len(id) < 2:
|
if len(id) < 2:
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
p = self.Process(
|
p = cls.Process(
|
||||||
target=self._test_recursion, args=(wconn, id+[i])
|
target=cls._test_recursion, args=(wconn, id+[i])
|
||||||
)
|
)
|
||||||
p.start()
|
p.start()
|
||||||
p.join()
|
p.join()
|
||||||
|
@ -342,7 +352,8 @@ def queue_full(q, maxsize):
|
||||||
class _TestQueue(BaseTestCase):
|
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()
|
child_can_start.wait()
|
||||||
for i in range(6):
|
for i in range(6):
|
||||||
queue.get()
|
queue.get()
|
||||||
|
@ -406,7 +417,8 @@ class _TestQueue(BaseTestCase):
|
||||||
|
|
||||||
proc.join()
|
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()
|
child_can_start.wait()
|
||||||
#queue.put(1)
|
#queue.put(1)
|
||||||
queue.put(2)
|
queue.put(2)
|
||||||
|
@ -467,7 +479,8 @@ class _TestQueue(BaseTestCase):
|
||||||
|
|
||||||
proc.join()
|
proc.join()
|
||||||
|
|
||||||
def _test_fork(self, queue):
|
@classmethod
|
||||||
|
def _test_fork(cls, queue):
|
||||||
for i in range(10, 20):
|
for i in range(10, 20):
|
||||||
queue.put(i)
|
queue.put(i)
|
||||||
# note that at this point the items may only be buffered, so the
|
# note that at this point the items may only be buffered, so the
|
||||||
|
@ -515,7 +528,8 @@ class _TestQueue(BaseTestCase):
|
||||||
q.get()
|
q.get()
|
||||||
self.assertEqual(q.qsize(), 0)
|
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):
|
for obj in iter(q.get, None):
|
||||||
time.sleep(DELTA)
|
time.sleep(DELTA)
|
||||||
q.task_done()
|
q.task_done()
|
||||||
|
@ -627,7 +641,8 @@ class _TestSemaphore(BaseTestCase):
|
||||||
|
|
||||||
class _TestCondition(BaseTestCase):
|
class _TestCondition(BaseTestCase):
|
||||||
|
|
||||||
def f(self, cond, sleeping, woken, timeout=None):
|
@classmethod
|
||||||
|
def f(cls, cond, sleeping, woken, timeout=None):
|
||||||
cond.acquire()
|
cond.acquire()
|
||||||
sleeping.release()
|
sleeping.release()
|
||||||
cond.wait(timeout)
|
cond.wait(timeout)
|
||||||
|
@ -759,7 +774,8 @@ class _TestCondition(BaseTestCase):
|
||||||
|
|
||||||
class _TestEvent(BaseTestCase):
|
class _TestEvent(BaseTestCase):
|
||||||
|
|
||||||
def _test_event(self, event):
|
@classmethod
|
||||||
|
def _test_event(cls, event):
|
||||||
time.sleep(TIMEOUT2)
|
time.sleep(TIMEOUT2)
|
||||||
event.set()
|
event.set()
|
||||||
|
|
||||||
|
@ -812,8 +828,9 @@ class _TestValue(BaseTestCase):
|
||||||
('c', latin('x'), latin('y'))
|
('c', latin('x'), latin('y'))
|
||||||
]
|
]
|
||||||
|
|
||||||
def _test(self, values):
|
@classmethod
|
||||||
for sv, cv in zip(values, self.codes_values):
|
def _test(cls, values):
|
||||||
|
for sv, cv in zip(values, cls.codes_values):
|
||||||
sv.value = cv[2]
|
sv.value = cv[2]
|
||||||
|
|
||||||
|
|
||||||
|
@ -868,7 +885,8 @@ class _TestArray(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes',)
|
ALLOWED_TYPES = ('processes',)
|
||||||
|
|
||||||
def f(self, seq):
|
@classmethod
|
||||||
|
def f(cls, seq):
|
||||||
for i in range(1, len(seq)):
|
for i in range(1, len(seq)):
|
||||||
seq[i] += seq[i-1]
|
seq[i] += seq[i-1]
|
||||||
|
|
||||||
|
@ -1211,7 +1229,8 @@ class _TestRemoteManager(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('manager',)
|
ALLOWED_TYPES = ('manager',)
|
||||||
|
|
||||||
def _putter(self, address, authkey):
|
@classmethod
|
||||||
|
def _putter(cls, address, authkey):
|
||||||
manager = QueueManager2(
|
manager = QueueManager2(
|
||||||
address=address, authkey=authkey, serializer=SERIALIZER
|
address=address, authkey=authkey, serializer=SERIALIZER
|
||||||
)
|
)
|
||||||
|
@ -1249,7 +1268,8 @@ class _TestRemoteManager(BaseTestCase):
|
||||||
|
|
||||||
class _TestManagerRestart(BaseTestCase):
|
class _TestManagerRestart(BaseTestCase):
|
||||||
|
|
||||||
def _putter(self, address, authkey):
|
@classmethod
|
||||||
|
def _putter(cls, address, authkey):
|
||||||
manager = QueueManager(
|
manager = QueueManager(
|
||||||
address=address, authkey=authkey, serializer=SERIALIZER)
|
address=address, authkey=authkey, serializer=SERIALIZER)
|
||||||
manager.connect()
|
manager.connect()
|
||||||
|
@ -1288,7 +1308,8 @@ class _TestConnection(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes', 'threads')
|
ALLOWED_TYPES = ('processes', 'threads')
|
||||||
|
|
||||||
def _echo(self, conn):
|
@classmethod
|
||||||
|
def _echo(cls, conn):
|
||||||
for msg in iter(conn.recv_bytes, SENTINEL):
|
for msg in iter(conn.recv_bytes, SENTINEL):
|
||||||
conn.send_bytes(msg)
|
conn.send_bytes(msg)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
@ -1437,8 +1458,9 @@ class _TestListenerClient(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes', 'threads')
|
ALLOWED_TYPES = ('processes', 'threads')
|
||||||
|
|
||||||
def _test(self, address):
|
@classmethod
|
||||||
conn = self.connection.Client(address)
|
def _test(cls, address):
|
||||||
|
conn = cls.connection.Client(address)
|
||||||
conn.send('hello')
|
conn.send('hello')
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@ -1599,7 +1621,8 @@ class _TestSharedCTypes(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes',)
|
ALLOWED_TYPES = ('processes',)
|
||||||
|
|
||||||
def _double(self, x, y, foo, arr, string):
|
@classmethod
|
||||||
|
def _double(cls, x, y, foo, arr, string):
|
||||||
x.value *= 2
|
x.value *= 2
|
||||||
y.value *= 2
|
y.value *= 2
|
||||||
foo.x *= 2
|
foo.x *= 2
|
||||||
|
@ -1647,7 +1670,8 @@ class _TestFinalize(BaseTestCase):
|
||||||
|
|
||||||
ALLOWED_TYPES = ('processes',)
|
ALLOWED_TYPES = ('processes',)
|
||||||
|
|
||||||
def _test_finalize(self, conn):
|
@classmethod
|
||||||
|
def _test_finalize(cls, conn):
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1741,7 +1765,8 @@ class _TestLogging(BaseTestCase):
|
||||||
logger.info('nor will this')
|
logger.info('nor will this')
|
||||||
logger.setLevel(LOG_LEVEL)
|
logger.setLevel(LOG_LEVEL)
|
||||||
|
|
||||||
def _test_level(self, conn):
|
@classmethod
|
||||||
|
def _test_level(cls, conn):
|
||||||
logger = multiprocessing.get_logger()
|
logger = multiprocessing.get_logger()
|
||||||
conn.send(logger.getEffectiveLevel())
|
conn.send(logger.getEffectiveLevel())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue