diff options
author | Charlie Zhao <68189100+CharlieZhao95@users.noreply.github.com> | 2022-02-26 04:17:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-26 04:17:13 (GMT) |
commit | e466faa9df9a1bd377d9725de5484471bc4af8d0 (patch) | |
tree | fc1e208390aab53f622971b10c8799bc4159ef1c /Doc/library/multiprocessing.rst | |
parent | 5ab745fc51e159ead28b523414e52f0bcc1ef353 (diff) | |
download | cpython-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 'Doc/library/multiprocessing.rst')
-rw-r--r-- | Doc/library/multiprocessing.rst | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index cbbe184..ee40688 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -485,7 +485,9 @@ The :mod:`multiprocessing` package mostly replicates the API of the to ``True`` or ``False``. If ``None`` (the default), this flag will be inherited from the creating process. - By default, no arguments are passed to *target*. + By default, no arguments are passed to *target*. The *args* argument, + which defaults to ``()``, can be used to specify a list or tuple of the arguments + to pass to *target*. If a subclass overrides the constructor, it must make sure it invokes the base class constructor (:meth:`Process.__init__`) before doing anything else @@ -503,6 +505,19 @@ The :mod:`multiprocessing` package mostly replicates the API of the the target argument, if any, with sequential and keyword arguments taken from the *args* and *kwargs* arguments, respectively. + Using a list or tuple as the *args* argument passed to :class:`Process` + achieves the same effect. + + Example:: + + >>> from multiprocessing import Process + >>> p = Process(target=print, args=[1]) + >>> p.run() + 1 + >>> p = Process(target=print, args=(1,)) + >>> p.run() + 1 + .. method:: start() Start the process's activity. |