This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients docs@python, tim.peters
Date 2021-11-06.04:02:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636171321.93.0.670075505099.issue45735@roundup.psfhosted.org>
In-reply-to
Content
A number of contexts allow specifying a tuple of arguments to be passed later to a function. The Thread constructor is a fine example, and happened to come up (again! for me) here today:

https://stackoverflow.com/questions/69858950/why-do-we-have-to-add-comma-in-args-in-python-multithreading/69859068

This often confuses especially newbies, because the function they intend to parallelize often takes only a single argument, and Python's syntax for a 1-element tuple actually _requires_ parentheses in the context of an argument list, with a naked trailing comma:

t = threading.Thread(target=access, args=(thread_number,))

It "looks weird" to people.

I'm not suggesting to change that, but instead to officially bless the workaround I've seen very often in real code: use a list instead.

t = threading.Thread(target=access, args=[thread_number])

Nobody scratches their head over what that means.

CPython's implementations typically couldn't care less what kind of sequence is used, and none that I'm aware of verify that it's specifically a tuple. The implementations just go on to do some simple variation of

    self.target(*self.args)

Tuple or list makes no real difference. I'm not really keen to immortalize the "any sequence type whatsoever that just happens to work" implementation behavior, but am keen to promise that a list specifically will work. A lot of code already relies on it.
History
Date User Action Args
2021-11-06 04:02:01tim.peterssetrecipients: + tim.peters, docs@python
2021-11-06 04:02:01tim.peterssetmessageid: <1636171321.93.0.670075505099.issue45735@roundup.psfhosted.org>
2021-11-06 04:02:01tim.peterslinkissue45735 messages
2021-11-06 04:02:01tim.peterscreate