summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorCharlie Zhao <68189100+CharlieZhao95@users.noreply.github.com>2022-02-26 04:17:13 (GMT)
committerGitHub <noreply@github.com>2022-02-26 04:17:13 (GMT)
commite466faa9df9a1bd377d9725de5484471bc4af8d0 (patch)
treefc1e208390aab53f622971b10c8799bc4159ef1c /Lib/test/test_threading.py
parent5ab745fc51e159ead28b523414e52f0bcc1ef353 (diff)
downloadcpython-e466faa9df9a1bd377d9725de5484471bc4af8d0.zip
cpython-e466faa9df9a1bd377d9725de5484471bc4af8d0.tar.gz
cpython-e466faa9df9a1bd377d9725de5484471bc4af8d0.tar.bz2
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_threading.py')
-rw-r--r--Lib/test/test_threading.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 48305714..16c6934 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -123,6 +123,32 @@ class ThreadTests(BaseTestCase):
thread = threading.Thread(target=func)
self.assertEqual(thread.name, "Thread-5 (func)")
+ def test_args_argument(self):
+ # bpo-45735: Using list or tuple as *args* in constructor could
+ # achieve the same effect.
+ num_list = [1]
+ num_tuple = (1,)
+
+ str_list = ["str"]
+ str_tuple = ("str",)
+
+ list_in_tuple = ([1],)
+ tuple_in_list = [(1,)]
+
+ test_cases = (
+ (num_list, lambda arg: self.assertEqual(arg, 1)),
+ (num_tuple, lambda arg: self.assertEqual(arg, 1)),
+ (str_list, lambda arg: self.assertEqual(arg, "str")),
+ (str_tuple, lambda arg: self.assertEqual(arg, "str")),
+ (list_in_tuple, lambda arg: self.assertEqual(arg, [1])),
+ (tuple_in_list, lambda arg: self.assertEqual(arg, (1,)))
+ )
+
+ for args, target in test_cases:
+ with self.subTest(target=target, args=args):
+ t = threading.Thread(target=target, args=args)
+ t.start()
+
@cpython_only
def test_disallow_instantiation(self):
# Ensure that the type disallows instantiation (bpo-43916)