Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26899f4

Browse files
committed
Merged revisions 86130 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent 59b7c70 commit 26899f4

1 file changed

Lines changed: 49 additions & 24 deletions

File tree

Lib/test/test_multiprocessing.py

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ def assertReturnsIfImplemented(self, value, func, *args):
115115
else:
116116
return self.assertEqual(value, res)
117117

118+
# For the sanity of Windows users, rather than crashing or freezing in
119+
# multiple ways.
120+
def __reduce__(self, *args):
121+
raise NotImplementedError("shouldn't try to pickle a test case")
122+
123+
__reduce_ex__ = __reduce__
124+
118125
#
119126
# Return the value of a semaphore
120127
#
@@ -153,12 +160,13 @@ def test_current(self):
153160
self.assertEqual(current.ident, os.getpid())
154161
self.assertEqual(current.exitcode, None)
155162

156-
def _test(self, q, *args, **kwds):
157-
current = self.current_process()
163+
@classmethod
164+
def _test(cls, q, *args, **kwds):
165+
current = cls.current_process()
158166
q.put(args)
159167
q.put(kwds)
160168
q.put(current.name)
161-
if self.TYPE != 'threads':
169+
if cls.TYPE != 'threads':
162170
q.put(bytes(current.authkey))
163171
q.put(current.pid)
164172

@@ -201,7 +209,8 @@ def test_process(self):
201209
self.assertEquals(p.is_alive(), False)
202210
self.assertTrue(p not in self.active_children())
203211

204-
def _test_terminate(self):
212+
@classmethod
213+
def _test_terminate(cls):
205214
time.sleep(1000)
206215

207216
def test_terminate(self):
@@ -250,13 +259,14 @@ def test_active_children(self):
250259
p.join()
251260
self.assertTrue(p not in self.active_children())
252261

253-
def _test_recursion(self, wconn, id):
262+
@classmethod
263+
def _test_recursion(cls, wconn, id):
254264
from multiprocessing import forking
255265
wconn.send(id)
256266
if len(id) < 2:
257267
for i in range(2):
258-
p = self.Process(
259-
target=self._test_recursion, args=(wconn, id+[i])
268+
p = cls.Process(
269+
target=cls._test_recursion, args=(wconn, id+[i])
260270
)
261271
p.start()
262272
p.join()
@@ -339,7 +349,8 @@ def queue_full(q, maxsize):
339349
class _TestQueue(BaseTestCase):
340350

341351

342-
def _test_put(self, queue, child_can_start, parent_can_continue):
352+
@classmethod
353+
def _test_put(cls, queue, child_can_start, parent_can_continue):
343354
child_can_start.wait()
344355
for i in range(6):
345356
queue.get()
@@ -403,7 +414,8 @@ def test_put(self):
403414

404415
proc.join()
405416

406-
def _test_get(self, queue, child_can_start, parent_can_continue):
417+
@classmethod
418+
def _test_get(cls, queue, child_can_start, parent_can_continue):
407419
child_can_start.wait()
408420
#queue.put(1)
409421
queue.put(2)
@@ -464,7 +476,8 @@ def test_get(self):
464476

465477
proc.join()
466478

467-
def _test_fork(self, queue):
479+
@classmethod
480+
def _test_fork(cls, queue):
468481
for i in range(10, 20):
469482
queue.put(i)
470483
# note that at this point the items may only be buffered, so the
@@ -512,7 +525,8 @@ def test_qsize(self):
512525
q.get()
513526
self.assertEqual(q.qsize(), 0)
514527

515-
def _test_task_done(self, q):
528+
@classmethod
529+
def _test_task_done(cls, q):
516530
for obj in iter(q.get, None):
517531
time.sleep(DELTA)
518532
q.task_done()
@@ -624,7 +638,8 @@ def test_timeout(self):
624638

625639
class _TestCondition(BaseTestCase):
626640

627-
def f(self, cond, sleeping, woken, timeout=None):
641+
@classmethod
642+
def f(cls, cond, sleeping, woken, timeout=None):
628643
cond.acquire()
629644
sleeping.release()
630645
cond.wait(timeout)
@@ -756,7 +771,8 @@ def test_timeout(self):
756771

757772
class _TestEvent(BaseTestCase):
758773

759-
def _test_event(self, event):
774+
@classmethod
775+
def _test_event(cls, event):
760776
time.sleep(TIMEOUT2)
761777
event.set()
762778

@@ -809,8 +825,9 @@ class _TestValue(BaseTestCase):
809825
('c', latin('x'), latin('y'))
810826
]
811827

812-
def _test(self, values):
813-
for sv, cv in zip(values, self.codes_values):
828+
@classmethod
829+
def _test(cls, values):
830+
for sv, cv in zip(values, cls.codes_values):
814831
sv.value = cv[2]
815832

816833

@@ -865,7 +882,8 @@ class _TestArray(BaseTestCase):
865882

866883
ALLOWED_TYPES = ('processes',)
867884

868-
def f(self, seq):
885+
@classmethod
886+
def f(cls, seq):
869887
for i in range(1, len(seq)):
870888
seq[i] += seq[i-1]
871889

@@ -1176,7 +1194,8 @@ class _TestRemoteManager(BaseTestCase):
11761194

11771195
ALLOWED_TYPES = ('manager',)
11781196

1179-
def _putter(self, address, authkey):
1197+
@classmethod
1198+
def _putter(cls, address, authkey):
11801199
manager = QueueManager2(
11811200
address=address, authkey=authkey, serializer=SERIALIZER
11821201
)
@@ -1214,7 +1233,8 @@ def test_remote(self):
12141233

12151234
class _TestManagerRestart(BaseTestCase):
12161235

1217-
def _putter(self, address, authkey):
1236+
@classmethod
1237+
def _putter(cls, address, authkey):
12181238
manager = QueueManager(
12191239
address=address, authkey=authkey, serializer=SERIALIZER)
12201240
manager.connect()
@@ -1253,7 +1273,8 @@ class _TestConnection(BaseTestCase):
12531273

12541274
ALLOWED_TYPES = ('processes', 'threads')
12551275

1256-
def _echo(self, conn):
1276+
@classmethod
1277+
def _echo(cls, conn):
12571278
for msg in iter(conn.recv_bytes, SENTINEL):
12581279
conn.send_bytes(msg)
12591280
conn.close()
@@ -1402,8 +1423,9 @@ class _TestListenerClient(BaseTestCase):
14021423

14031424
ALLOWED_TYPES = ('processes', 'threads')
14041425

1405-
def _test(self, address):
1406-
conn = self.connection.Client(address)
1426+
@classmethod
1427+
def _test(cls, address):
1428+
conn = cls.connection.Client(address)
14071429
conn.send('hello')
14081430
conn.close()
14091431

@@ -1564,7 +1586,8 @@ class _TestSharedCTypes(BaseTestCase):
15641586

15651587
ALLOWED_TYPES = ('processes',)
15661588

1567-
def _double(self, x, y, foo, arr, string):
1589+
@classmethod
1590+
def _double(cls, x, y, foo, arr, string):
15681591
x.value *= 2
15691592
y.value *= 2
15701593
foo.x *= 2
@@ -1612,7 +1635,8 @@ class _TestFinalize(BaseTestCase):
16121635

16131636
ALLOWED_TYPES = ('processes',)
16141637

1615-
def _test_finalize(self, conn):
1638+
@classmethod
1639+
def _test_finalize(cls, conn):
16161640
class Foo(object):
16171641
pass
16181642

@@ -1706,7 +1730,8 @@ def test_enable_logging(self):
17061730
logger.info('nor will this')
17071731
logger.setLevel(LOG_LEVEL)
17081732

1709-
def _test_level(self, conn):
1733+
@classmethod
1734+
def _test_level(cls, conn):
17101735
logger = multiprocessing.get_logger()
17111736
conn.send(logger.getEffectiveLevel())
17121737

0 commit comments

Comments
 (0)