Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83344ec

Browse files
committed
Move out of a .. note into the main text. mention in the high level Process description.
1 parent 607ae4a commit 83344ec

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

Doc/library/multiprocessing.rst

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ To show the individual process IDs involved, here is an expanded example::
9797
For an explanation of why the ``if __name__ == '__main__'`` part is
9898
necessary, see :ref:`multiprocessing-programming`.
9999

100+
The arguments to :class:`Process` usually need to be unpickleable from within
101+
the child process. If you tried typing the above example directly into REPL it
102+
could lead to an :exc:`AttributeError` in the child process trying to locate the
103+
*f* function in the ``__main__`` module.
100104

101105

102106
.. _multiprocessing-start-methods:
@@ -544,38 +548,36 @@ The :mod:`multiprocessing` package mostly replicates the API of the
544548
base class constructor (:meth:`Process.__init__`) before doing anything else
545549
to the process.
546550

547-
.. versionchanged:: 3.3
548-
Added the *daemon* parameter.
551+
In general, all arguments to :meth:`Process.__init__` must be picklable.
552+
This is particularly notable when trying to create a :class:`Process` or
553+
use a :class:`~concurrent.futures.ProcessPoolExecutor` from a REPL with a
554+
locally defined *target* function.
549555

550-
.. note::
556+
Passing a callable object defined in the current REPL session raises an
557+
:exc:`AttributeError` exception when starting the process as such as
558+
*target* must have been defined within an importable module to under to be
559+
unpickled.
551560

552-
In general, all arguments to :meth:`Process.__init__` must be picklable.
553-
This is particularly notable when trying to create a :class:`Process` or
554-
use a :class:`~concurrent.futures.ProcessPoolExecutor` from a REPL with a
555-
locally defined *target* function.
561+
Example::
556562

557-
Passing a callable object defined in the current REPL session raises an
558-
:exc:`AttributeError` exception when starting the process as such as
559-
*target* must have been defined within an importable module to under to be
560-
unpickled.
561-
562-
Example::
563+
>>> import multiprocessing as mp
564+
>>> def knigit():
565+
... print("knee!")
566+
...
567+
>>> mp.Process(target=knigit).start()
568+
>>> Traceback (most recent call last):
569+
File ".../multiprocessing/spawn.py", line ..., in spawn_main
570+
File ".../multiprocessing/spawn.py", line ..., in _main
571+
AttributeError: module '__main__' has no attribute 'knigit'
563572

564-
>>> import multiprocessing as mp
565-
>>> def knigit():
566-
... print("knee!")
567-
...
568-
>>> mp.Process(target=knigit).start()
569-
>>> Traceback (most recent call last):
570-
File ".../multiprocessing/spawn.py", line ..., in spawn_main
571-
File ".../multiprocessing/spawn.py", line ..., in _main
572-
AttributeError: module '__main__' has no attribute 'knigit'
573+
See :ref:`multiprocessing-programming-spawn`.
573574

574-
See :ref:`multiprocessing-programming-spawn`.
575+
While this restriction is not true if using the ``"fork"`` start method,
576+
as of Python ``3.14`` that is no longer the default on any platform. See
577+
:ref:`multiprocessing-start-methods`.
575578

576-
While this restriction is not true if using the ``"fork"`` start method,
577-
as of Python ``3.14`` that is no longer the default on any platform. See
578-
:ref:`multiprocessing-start-methods`.
579+
.. versionchanged:: 3.3
580+
Added the *daemon* parameter.
579581

580582
.. method:: run()
581583

0 commit comments

Comments
 (0)