The :class:`Process` class
-~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^
In :mod:`multiprocessing`, processes are spawned by creating a :class:`Process`
object and then calling its :meth:`~Process.start` method. :class:`Process`
.. _multiprocessing-start-methods:
Contexts and start methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^
Depending on the platform, :mod:`multiprocessing` supports three ways
to start a process. These *start methods* are
Exchanging objects between processes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:mod:`multiprocessing` supports two types of communication channel between
processes:
Synchronization between processes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:mod:`multiprocessing` contains equivalents of all the synchronization
primitives from :mod:`threading`. For instance one can use a lock to ensure
Sharing state between processes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
As mentioned above, when doing concurrent programming it is usually best to
avoid using shared state as far as possible. This is particularly true when
Using a pool of workers
-~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^
The :class:`~multiprocessing.pool.Pool` class represents a pool of worker
processes. It has methods which allows tasks to be offloaded to the worker
:class:`Process` and exceptions
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. class:: Process(group=None, target=None, name=None, args=(), kwargs={}, \
*, daemon=None)
Raised by methods with a timeout when the timeout expires.
Pipes and Queues
-~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^
When using multiple processes, one generally uses message passing for
communication between processes and avoids having to use any synchronization
Miscellaneous
-~~~~~~~~~~~~~
+^^^^^^^^^^^^^
.. function:: active_children()
Connection Objects
-~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^
.. currentmodule:: multiprocessing.connection
Synchronization primitives
-~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^
.. currentmodule:: multiprocessing
Shared :mod:`ctypes` Objects
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It is possible to create shared objects using shared memory which can be
inherited by child processes.
The :mod:`multiprocessing.sharedctypes` module
->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+""""""""""""""""""""""""""""""""""""""""""""""
.. module:: multiprocessing.sharedctypes
:synopsis: Allocate ctypes objects from shared memory.
.. _multiprocessing-managers:
Managers
-~~~~~~~~
+^^^^^^^^
Managers provide a way to create data which can be shared between different
processes, including sharing over a network between processes running on
Customized managers
->>>>>>>>>>>>>>>>>>>
+"""""""""""""""""""
To create one's own manager, one creates a subclass of :class:`BaseManager` and
uses the :meth:`~BaseManager.register` classmethod to register new types or
Using a remote manager
->>>>>>>>>>>>>>>>>>>>>>
+""""""""""""""""""""""
It is possible to run a manager server on one machine and have clients use it
from other machines (assuming that the firewalls involved allow it).
.. _multiprocessing-proxy_objects:
Proxy Objects
-~~~~~~~~~~~~~
+^^^^^^^^^^^^^
A proxy is an object which *refers* to a shared object which lives (presumably)
in a different process. The shared object is said to be the *referent* of the
Cleanup
->>>>>>>
+"""""""
A proxy object uses a weakref callback so that when it gets garbage collected it
deregisters itself from the manager which owns its referent.
Process Pools
-~~~~~~~~~~~~~
+^^^^^^^^^^^^^
.. module:: multiprocessing.pool
:synopsis: Create pools of processes.
.. _multiprocessing-listeners-clients:
Listeners and Clients
-~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^
.. module:: multiprocessing.connection
:synopsis: API for dealing with sockets.
.. _multiprocessing-address-formats:
Address Formats
->>>>>>>>>>>>>>>
+"""""""""""""""
* An ``'AF_INET'`` address is a tuple of the form ``(hostname, port)`` where
*hostname* is a string and *port* is an integer.
.. _multiprocessing-auth-keys:
Authentication keys
-~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^
When one uses :meth:`Connection.recv <Connection.recv>`, the
data received is automatically
Logging
-~~~~~~~
+^^^^^^^
Some support for logging is available. Note, however, that the :mod:`logging`
package does not use process shared locks so it is possible (depending on the
The :mod:`multiprocessing.dummy` module
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. module:: multiprocessing.dummy
:synopsis: Dumb wrapper around threading.
All start methods
-~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^
The following applies to all start methods.
For more information, see :issue:`5155`, :issue:`5313` and :issue:`5331`
The *spawn* and *forkserver* start methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are a few extra restriction which don't apply to the *fork*
start method.