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

Skip to content

Commit d840b8d

Browse files
committed
whatsnew: multiprocessing start methods and context (#8713 and #18999)
Also tweaked the docs a bit to use our standard style for versionadded/changed. (I'm guessing there are other places in the multiprocessing docs where similar tweaks should be made.)
1 parent f2e677c commit d840b8d

3 files changed

Lines changed: 47 additions & 19 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ to start a process. These *start methods* are
136136
Available on Unix platforms which support passing file descriptors
137137
over Unix pipes.
138138

139-
Before Python 3.4 *fork* was the only option available on Unix. Also,
140-
prior to Python 3.4, child processes would inherit all the parents
141-
inheritable handles on Windows.
139+
.. versionchanged:: 3.4
140+
*span* added on all unix platforms, and *forkserver* added for
141+
some unix platforms.
142+
Child processes no longer inherit all of the parents inheritable
143+
handles on Windows.
142144

143145
On Unix using the *spawn* or *forkserver* start methods will also
144146
start a *semaphore tracker* process which tracks the unlinked named
@@ -1853,25 +1855,30 @@ with the :class:`Pool` class.
18531855
callbacks and has a parallel map implementation.
18541856

18551857
*processes* is the number of worker processes to use. If *processes* is
1856-
``None`` then the number returned by :func:`os.cpu_count` is used. If
1857-
*initializer* is not ``None`` then each worker process will call
1858+
``None`` then the number returned by :func:`os.cpu_count` is used.
1859+
1860+
If *initializer* is not ``None`` then each worker process will call
18581861
``initializer(*initargs)`` when it starts.
18591862

1863+
*maxtasksperchild* is the number of tasks a worker process can complete
1864+
before it will exit and be replaced with a fresh worker process, to enable
1865+
unused resources to be freed. The default *maxtasksperchild* is None, which
1866+
means worker processes will live as long as the pool.
1867+
1868+
*context* can be used to specify the context used for starting
1869+
the worker processes. Usually a pool is created using the
1870+
function :func:`multiprocessing.Pool` or the :meth:`Pool` method
1871+
of a context object. In both cases *context* is set
1872+
appropriately.
1873+
18601874
Note that the methods of the pool object should only be called by
18611875
the process which created the pool.
18621876

18631877
.. versionadded:: 3.2
1864-
*maxtasksperchild* is the number of tasks a worker process can complete
1865-
before it will exit and be replaced with a fresh worker process, to enable
1866-
unused resources to be freed. The default *maxtasksperchild* is None, which
1867-
means worker processes will live as long as the pool.
1878+
*maxtasksperchild*
18681879

18691880
.. versionadded:: 3.4
1870-
*context* can be used to specify the context used for starting
1871-
the worker processes. Usually a pool is created using the
1872-
function :func:`multiprocessing.Pool` or the :meth:`Pool` method
1873-
of a context object. In both cases *context* is set
1874-
appropriately.
1881+
*context*
18751882

18761883
.. note::
18771884

Doc/whatsnew/3.4.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,25 @@ On Unix, two new :ref:`start methods <multiprocessing-start-methods>`
10631063
(``spawn`` and ``forkserver``) have been added for starting processes using
10641064
:mod:`multiprocessing`. These make the mixing of processes with threads more
10651065
robust, and the ``spawn`` method matches the semantics that multiprocessing has
1066-
always used on Windows. (Contributed by Richard Oudkerk in :issue:`8713`).
1067-
1068-
Also, except when using the old *fork* start method, child processes
1069-
will no longer inherit unneeded handles/file descriptors from their parents
1070-
(part of :issue:`8713`).
1066+
always used on Windows. New function
1067+
:func:`~multiprocessing.get_all_start_methods` reports all start methods
1068+
available on the platform, :func:`~multiprocessing.get_start_method` reports
1069+
the current start method, and :func:`~multiprocessing.set_start_method` sets
1070+
the start method. (Contributed by Richard Oudkerk in :issue:`8713`).
1071+
1072+
:mod:`multiprocessing` also now has the concept of a ``context``, which
1073+
determines how child processes are created. New function
1074+
:func:`~multiprocessing.get_context` returns a context that uses a specified
1075+
start method. It has the same API as the :mod:`multiprocessing` module itself,
1076+
so you can use it to create :class:`~multiprocessing.pool.Pool`\ s and other
1077+
objects that will operate within that context. This allows a framework and an
1078+
application or different parts of the same application to use multiprocessing
1079+
without interfering with each other. (Contributed by Richard Oudkerk in
1080+
:issue:`18999`.)
1081+
1082+
Except when using the old *fork* start method, child processes no longer
1083+
inherit unneeded handles/file descriptors from their parents (part of
1084+
:issue:`8713`).
10711085

10721086
:mod:`multiprocessing` now relies on :mod:`runpy` (which implements the
10731087
``-m`` switch) to initialise ``__main__`` appropriately in child processes

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ Library
16361636

16371637
- Issue #18281: Unused stat constants removed from `tarfile`.
16381638

1639+
- Issue #18999: Multiprocessing now supports 'contexts' with the same API
1640+
as the module, but bound to specified start methods.
1641+
16391642
- Issue #18468: The re.split, re.findall, and re.sub functions and the group()
16401643
and groups() methods of match object now always return a string or a bytes
16411644
object.
@@ -2051,6 +2054,10 @@ Library
20512054
- Issue #18532: Change the builtin hash algorithms' names to lower case names
20522055
as promised by hashlib's documentation.
20532056

2057+
- Issue #8713: add new spwan and forkserver start methods, and new functions
2058+
get_all_start_methods, get_start_method, and set_start_method, to
2059+
multiprocessing.
2060+
20542061
- Issue #18405: Improve the entropy of crypt.mksalt().
20552062

20562063
- Issue #12015: The tempfile module now uses a suffix of 8 random characters

0 commit comments

Comments
 (0)