Skip to content
Prev Previous commit
Next Next commit
move back to a note, it keeps it clear that this is "special"
  • Loading branch information
gpshead committed Jul 27, 2025
commit 4ad605aa1e3bee48da97ed134c354acd8dcf2467
46 changes: 24 additions & 22 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -548,33 +548,35 @@
base class constructor (:meth:`Process.__init__`) before doing anything else
to the process.

In general, all arguments to :meth:`Process.__init__` must be picklable.
This is particularly notable when trying to create a :class:`Process` or
use a :class:`~concurrent.futures.ProcessPoolExecutor` from a REPL with a
locally defined *target* function.
.. note::

Passing a callable object defined in the current REPL session raises an
:exc:`AttributeError` exception when starting the process as such as
*target* must have been defined within an importable module to under to be
unpickled.
In general, all arguments to :meth:`Process.__init__` must be picklable.

Check warning on line 553 in Doc/library/multiprocessing.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: Process.__init__ [ref.meth]
This is particularly notable when trying to create a :class:`Process` or use
a :class:`concurrent.futures.ProcessPoolExecutor` from a REPL with a locally
defined *target* function.

Example::
Passing a callable object defined in the current REPL session raises an
:exc:`AttributeError` exception when starting the process as such as
*target* must have been defined within an importable module to under to be
unpickled.

>>> import multiprocessing as mp
>>> def knigit():
... print("knee!")
...
>>> mp.Process(target=knigit).start()
>>> Traceback (most recent call last):
File ".../multiprocessing/spawn.py", line ..., in spawn_main
File ".../multiprocessing/spawn.py", line ..., in _main
AttributeError: module '__main__' has no attribute 'knigit'
Example::

>>> import multiprocessing as mp
>>> def knigit():
... print("knee!")
...
>>> mp.Process(target=knigit).start()
>>> Traceback (most recent call last):
File ".../multiprocessing/spawn.py", line ..., in spawn_main
File ".../multiprocessing/spawn.py", line ..., in _main
AttributeError: module '__main__' has no attribute 'knigit'

See :ref:`multiprocessing-programming-spawn`.
See :ref:`multiprocessing-programming-spawn`.

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

.. versionchanged:: 3.3
Added the *daemon* parameter.
Expand Down
Loading