aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorCharlie Zhao <68189100+CharlieZhao95@users.noreply.github.com>2022-02-26 12:17:13 +0800
committerGitHub <noreply@github.com>2022-02-25 22:17:13 -0600
commite466faa9df9a1bd377d9725de5484471bc4af8d0 (patch)
treefc1e208390aab53f622971b10c8799bc4159ef1c /Lib/test/_test_multiprocessing.py
parent5ab745fc51e159ead28b523414e52f0bcc1ef353 (diff)
downloadcpython-e466faa9df9a1bd377d9725de5484471bc4af8d0.tar.gz
cpython-e466faa9df9a1bd377d9725de5484471bc4af8d0.zip
bpo-45735: Promise the long-time truth that `args=list` works (GH-30982)
For threads, and for multiprocessing, it's always been the case that ``args=list`` works fine when passed to ``Process()`` or ``Thread()``, and such code is common in the wild. But, according to the docs, only a tuple can be used. This brings the docs into synch with reality. Doc changes by Charlie Zhao. Co-authored-by: Tim Peters <tim.peters@gmail.com>
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index b2d656ab428..6b1b1677910 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -247,6 +247,30 @@ class _TestProcess(BaseTestCase):
self.assertEqual(current.ident, os.getpid())
self.assertEqual(current.exitcode, None)
+ def test_args_argument(self):
+ # bpo-45735: Using list or tuple as *args* in constructor could
+ # achieve the same effect.
+ args_cases = (1, "str", [1], (1,))
+ args_types = (list, tuple)
+
+ test_cases = itertools.product(args_cases, args_types)
+
+ for args, args_type in test_cases:
+ with self.subTest(args=args, args_type=args_type):
+ q = self.Queue(1)
+ # pass a tuple or list as args
+ p = self.Process(target=self._test_args, args=args_type((q, args)))
+ p.daemon = True
+ p.start()
+ child_args = q.get()
+ self.assertEqual(child_args, args)
+ p.join()
+ close_queue(q)
+
+ @classmethod
+ def _test_args(cls, q, arg):
+ q.put(arg)
+
def test_daemon_argument(self):
if self.TYPE == "threads":
self.skipTest('test not appropriate for {}'.format(self.TYPE))