10000 bpo-45735: Promise the long-time truth that `args=list` works by CharlieZhao95 · Pull Request #30982 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45735: Promise the long-time truth that args=list works #30982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add doc example to use list or tuple as *args*
  • Loading branch information
CharlieZhao95 committed Jan 27, 2022
commit 76f8d90ce562d6fc77a4491281d4e5c1cc256d46
15 changes: 14 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ class is implemented.
*name* is the thread name. By default, a unique name is constructed of
the form "Thread-N" where N is a small decimal number.

*args* is the argument tuple for the target invocation. Defaults to ().
*args* is a list or tuple of arguments for the target invocation. Defaults to ().

*kwargs* is a dictionary of keyword arguments for the target
invocation. Defaults to {}.
Expand All @@ -861,6 +861,19 @@ class is implemented.
the base class constructor (Thread.__init__()) before doing anything
else to the thread.

Example to use list or tuple as *args* in constructor:

>>> from threading import Thread
>>> def func_print(arg1, arg2):
... print(arg1, arg2)
>>> Thread(target=func_print, args=[1, 2]).run()
1 2
>>> Thread(target=func_print, args=["str1", "str2"]).run()
str1 str2
>>> Thread(target=func_print, args=(1, 2,)).run()
1 2
>>> Thread(target=func_print, args=("str1", "str2",)).run()
str1 str2
"""
assert group is None, "group argument must be None for now"
if kwargs is None:
Expand Down
0