@@ -97,6 +97,10 @@ To show the individual process IDs involved, here is an expanded example::
97
97
For an explanation of why the ``if __name__ == '__main__' `` part is
98
98
necessary, see :ref: `multiprocessing-programming `.
99
99
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.
100
104
101
105
102
106
.. _multiprocessing-start-methods :
@@ -544,38 +548,36 @@ The :mod:`multiprocessing` package mostly replicates the API of the
544
548
base class constructor (:meth: `Process.__init__ `) before doing anything else
545
549
to the process.
546
550
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.
549
555
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.
551
560
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::
556
562
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'
563
572
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 `.
573
574
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 `.
575
578
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.
579
581
580
582
.. method :: run()
581
583
0 commit comments