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

Skip to content

Commit 62b6a0d

Browse files
committed
Issue #26523: The multiprocessing thread pool (multiprocessing.dummy.Pool) was untested.
1 parent ecd5383 commit 62b6a0d

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

Lib/test/_test_multiprocessing.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,13 +1818,19 @@ def test_imap_unordered_handle_iterable_exception(self):
18181818
expected_values.remove(value)
18191819

18201820
def test_make_pool(self):
1821-
self.assertRaises(ValueError, multiprocessing.Pool, -1)
1822-
self.assertRaises(ValueError, multiprocessing.Pool, 0)
1821+
expected_error = (RemoteError if self.TYPE == 'manager'
1822+
else ValueError)
18231823

1824-
p = multiprocessing.Pool(3)
1825-
self.assertEqual(3, len(p._pool))
1826-
p.close()
1827-
p.join()
1824+
self.assertRaises(expected_error, self.Pool, -1)
1825+
self.assertRaises(expected_error, self.Pool, 0)
1826+
1827+
if self.TYPE != 'manager':
1828+
p = self.Pool(3)
1829+
try:
1830+
self.assertEqual(3, len(p._pool))
1831+
finally:
1832+
p.close()
1833+
p.join()
18281834

18291835
def test_terminate(self):
18301836
result = self.pool.map_async(
@@ -1833,7 +1839,8 @@ def test_terminate(self):
18331839
self.pool.terminate()
18341840
join = TimingWrapper(self.pool.join)
18351841
join()
1836-
self.assertLess(join.elapsed, 0.5)
1842+
# Sanity check the pool didn't wait for all tasks to finish
1843+
self.assertLess(join.elapsed, 2.0)
18371844

18381845
def test_empty_iterable(self):
18391846
# See Issue 12157
@@ -1851,7 +1858,7 @@ def test_context(self):
18511858
if self.TYPE == 'processes':
18521859
L = list(range(10))
18531860
expected = [sqr(i) for i in L]
1854-
with multiprocessing.Pool(2) as p:
1861+
with self.Pool(2) as p:
18551862
r = p.map_async(sqr, L)
18561863
self.assertEqual(r.get(), expected)
18571864
self.assertRaises(ValueError, p.map_async, sqr, L)
@@ -3834,7 +3841,7 @@ class ThreadsMixin(object):
38343841
connection = multiprocessing.dummy.connection
38353842
current_process = staticmethod(multiprocessing.dummy.current_process)
38363843
active_children = staticmethod(multiprocessing.dummy.active_children)
3837-
Pool = staticmethod(multiprocessing.Pool)
3844+
Pool = staticmethod(multiprocessing.dummy.Pool)
38383845
Pipe = staticmethod(multiprocessing.dummy.Pipe)
38393846
Queue = staticmethod(multiprocessing.dummy.Queue)
38403847
JoinableQueue = staticmethod(multiprocessing.dummy.JoinableQueue)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ Documentation
298298
Tests
299299
-----
300300

301+
- Issue #26523: The multiprocessing thread pool (multiprocessing.dummy.Pool)
302+
was untested.
303+
301304
- Issue #26015: Added new tests for pickling iterators of mutable sequences.
302305

303306
- Issue #26325: Added test.support.check_no_resource_warning() to check that

0 commit comments

Comments
 (0)