From 646225cd8d6912a7dc0cf9f1bc4869986857f2b1 Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 9 Jul 2025 01:08:24 +0900 Subject: [PATCH 01/11] Document the ctx parameter in some types in multiprocessing --- Doc/library/multiprocessing.rst | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 546876bd925db0..1ec5c8f7a5547c 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1660,7 +1660,7 @@ processes. attributes which allow one to use it to store and retrieve strings -- see documentation for :mod:`ctypes`. -.. function:: Array(typecode_or_type, size_or_initializer, *, lock=True) +.. function:: Array(typecode_or_type, size_or_initializer, *, lock=True, ctx=None) The same as :func:`RawArray` except that depending on the value of *lock* a process-safe synchronization wrapper may be returned instead of a raw ctypes @@ -1674,9 +1674,14 @@ processes. automatically protected by a lock, so it will not necessarily be "process-safe". + *ctx* is a context object, or ``None`` (use the current context). If ``None``, + calling this function will have the side effect of setting the current global + start method if it has not been set already. See the :func:`get_context` + function. + Note that *lock* is a keyword-only argument. -.. function:: Value(typecode_or_type, *args, lock=True) +.. function:: Value(typecode_or_type, *args, lock=True, ctx=None) The same as :func:`RawValue` except that depending on the value of *lock* a process-safe synchronization wrapper may be returned instead of a raw ctypes @@ -1689,6 +1694,11 @@ processes. automatically protected by a lock, so it will not necessarily be "process-safe". + *ctx* is a context object, or ``None`` (use the current context). If ``None``, + calling this function will have the side effect of setting the current global + start method if it has not been set already. See the :func:`get_context` + function. + Note that *lock* is a keyword-only argument. .. function:: copy(obj) @@ -1696,12 +1706,17 @@ processes. Return a ctypes object allocated from shared memory which is a copy of the ctypes object *obj*. -.. function:: synchronized(obj[, lock]) +.. function:: synchronized(obj, lock=None, ctx=None) Return a process-safe wrapper object for a ctypes object which uses *lock* to synchronize access. If *lock* is ``None`` (the default) then a :class:`multiprocessing.RLock` object is created automatically. + *ctx* is a context object, or ``None`` (use the current context). If ``None``, + calling this function will have the side effect of setting the current global + start method if it has not been set already. See the :func:`get_context` + function. + A synchronized wrapper will have two methods in addition to those of the object it wraps: :meth:`get_obj` returns the wrapped object and :meth:`get_lock` returns the lock object used for synchronization. @@ -1819,8 +1834,10 @@ their parent process exits. The manager classes are defined in the *serializer* must be ``'pickle'`` (use :mod:`pickle` serialization) or ``'xmlrpclib'`` (use :mod:`xmlrpc.client` serialization). - *ctx* is a context object, or ``None`` (use the current context). See the - :func:`get_context` function. + *ctx* is a context object, or ``None`` (use the current context). If ``None``, + calling this function will have the side effect of setting the current global + start method if it has not been set already. See the :func:`get_context` + function. *shutdown_timeout* is a timeout in seconds used to wait until the process used by the manager completes in the :meth:`shutdown` method. If the From 1b7a0eac06bf36e1c12fb79c0769009dc5fe1dc0 Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 9 Jul 2025 01:30:13 +0900 Subject: [PATCH 02/11] Update side effect document --- Doc/library/multiprocessing.rst | 43 ++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 1ec5c8f7a5547c..7df2ae3fed772a 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -867,6 +867,10 @@ For an example of the usage of queues for interprocess communication see locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + The usual :exc:`queue.Empty` and :exc:`queue.Full` exceptions from the standard library's :mod:`queue` module are raised to signal timeouts. @@ -977,6 +981,10 @@ For an example of the usage of queues for interprocess communication see It is a simplified :class:`Queue` type, very close to a locked :class:`Pipe`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + .. method:: close() Close the queue: release internal resources. @@ -1007,6 +1015,10 @@ For an example of the usage of queues for interprocess communication see :class:`JoinableQueue`, a :class:`Queue` subclass, is a queue which additionally has :meth:`task_done` and :meth:`join` methods. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + .. method:: task_done() Indicate that a formerly enqueued task is complete. Used by queue @@ -1361,6 +1373,10 @@ object -- see :ref:`multiprocessing-managers`. A barrier object: a clone of :class:`threading.Barrier`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + .. versionadded:: 3.3 .. class:: BoundedSemaphore([value]) @@ -1368,6 +1384,10 @@ object -- see :ref:`multiprocessing-managers`. A bounded semaphore object: a close analog of :class:`threading.BoundedSemaphore`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + A solitary difference from its close analog exists: its ``acquire`` method's first argument is named *block*, as is consistent with :meth:`Lock.acquire`. @@ -1388,6 +1408,10 @@ object -- see :ref:`multiprocessing-managers`. If *lock* is specified then it should be a :class:`Lock` or :class:`RLock` object from :mod:`multiprocessing`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + .. versionchanged:: 3.3 The :meth:`~threading.Condition.wait_for` method was added. @@ -1395,6 +1419,9 @@ object -- see :ref:`multiprocessing-managers`. A clone of :class:`threading.Event`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. .. class:: Lock() @@ -1410,6 +1437,10 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.Lock`` initialized with a default context. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + :class:`Lock` supports the :term:`context manager` protocol and thus may be used in :keyword:`with` statements. @@ -1467,6 +1498,10 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.RLock`` initialized with a default context. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + :class:`RLock` supports the :term:`context manager` protocol and thus may be used in :keyword:`with` statements. @@ -1526,6 +1561,10 @@ object -- see :ref:`multiprocessing-managers`. A semaphore object: a close analog of :class:`threading.Semaphore`. + If the global start method has not been set, calling this function will + have the side effect of setting the current global start method. + See the :func:`get_context` function. + A solitary difference from its close analog exists: its ``acquire`` method's first argument is named *block*, as is consistent with :meth:`Lock.acquire`. @@ -2330,7 +2369,9 @@ with the :class:`Pool` class. the worker processes. Usually a pool is created using the function :func:`multiprocessing.Pool` or the :meth:`Pool` method of a context object. In both cases *context* is set - appropriately. + appropriately. If ``None``, calling this function will have the side effect + of setting the current global start method if it has not been set already. + See the :func:`get_context` function. Note that the methods of the pool object should only be called by the process which created the pool. From 29b5cf3ebafe41826fbb908cb4a25ad0ac090a99 Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 9 Jul 2025 01:32:04 +0900 Subject: [PATCH 03/11] Update document --- Doc/library/multiprocessing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 7df2ae3fed772a..2ac397f655c3da 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1718,7 +1718,7 @@ processes. start method if it has not been set already. See the :func:`get_context` function. - Note that *lock* is a keyword-only argument. + Note that *lock* and ctx are keyword-only argument. .. function:: Value(typecode_or_type, *args, lock=True, ctx=None) @@ -1738,7 +1738,7 @@ processes. start method if it has not been set already. See the :func:`get_context` function. - Note that *lock* is a keyword-only argument. + Note that *lock* and *ctx* are keyword-only argument. .. function:: copy(obj) From 79626578ecec0eddf621355a05a6a626cbfabf6f Mon Sep 17 00:00:00 2001 From: AN Long Date: Wed, 9 Jul 2025 01:34:48 +0900 Subject: [PATCH 04/11] Fix marker --- Doc/library/multiprocessing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 2ac397f655c3da..bbed162ba07e62 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1718,7 +1718,7 @@ processes. start method if it has not been set already. See the :func:`get_context` function. - Note that *lock* and ctx are keyword-only argument. + Note that *lock* and *ctx* are keyword-only argument. .. function:: Value(typecode_or_type, *args, lock=True, ctx=None) From ed601274b119b70fd8bce65a55ff1b3a5b12a59b Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 23:11:49 +0900 Subject: [PATCH 05/11] argument -> parameters --- Doc/library/multiprocessing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index bbed162ba07e62..261e55166d75f3 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1718,7 +1718,7 @@ processes. start method if it has not been set already. See the :func:`get_context` function. - Note that *lock* and *ctx* are keyword-only argument. + Note that *lock* and *ctx* are keyword-only parameters. .. function:: Value(typecode_or_type, *args, lock=True, ctx=None) @@ -1738,7 +1738,7 @@ processes. start method if it has not been set already. See the :func:`get_context` function. - Note that *lock* and *ctx* are keyword-only argument. + Note that *lock* and *ctx* are keyword-only parameters. .. function:: copy(obj) From 881a347a0330c2ac3cbb05f6a033e2317510514a Mon Sep 17 00:00:00 2001 From: AN Long Date: Fri, 11 Jul 2025 00:11:03 +0900 Subject: [PATCH 06/11] Reduce duplication --- Doc/library/multiprocessing.rst | 92 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 261e55166d75f3..e1ab1ece7c203a 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -511,6 +511,17 @@ Reference The :mod:`multiprocessing` package mostly replicates the API of the :mod:`threading` module. +.. _global-start-method: + +Global start method +^^^^^^^^^^^^^^^^^^^ + +Calling some functions or methods, or creating some objects, will implicitly +set the global start method to the system's default if it is not already +set. This can only be done once. Therefore, if you need to change the +start method, you must do so before calling these functions or methods, or +creating these objects. + :class:`Process` and exceptions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -867,9 +878,8 @@ For an example of the usage of queues for interprocess communication see locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. The usual :exc:`queue.Empty` and :exc:`queue.Full` exceptions from the standard library's :mod:`queue` module are raised to signal timeouts. @@ -981,9 +991,8 @@ For an example of the usage of queues for interprocess communication see It is a simplified :class:`Queue` type, very close to a locked :class:`Pipe`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. .. method:: close() @@ -1015,9 +1024,8 @@ For an example of the usage of queues for interprocess communication see :class:`JoinableQueue`, a :class:`Queue` subclass, is a queue which additionally has :meth:`task_done` and :meth:`join` methods. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. .. method:: task_done() @@ -1131,8 +1139,8 @@ Miscellaneous :mod:`multiprocessing` module. If *method* is ``None`` then the default context is returned. Note that if - the global start method has not been set, this will set it to the - default method. + the global start method has not been set, this will set it. + See :ref:`global-start-method` for more details. Otherwise *method* should be ``'fork'``, ``'spawn'``, ``'forkserver'``. :exc:`ValueError` is raised if the specified start method is not available. See :ref:`multiprocessing-start-methods`. @@ -1143,10 +1151,9 @@ Miscellaneous Return the name of start method used for starting processes. - If the global start method has not been set and *allow_none* is - ``False``, then the start method is set to the default and the name - is returned. If the start method has not been set and *allow_none* is - ``True`` then ``None`` is returned. + If the start method is not set and *allow_none* is ``False``, the start + method is set to the default, and its name is returned. See + :ref:`global-start-method` for more details. The return value can be ``'fork'``, ``'spawn'``, ``'forkserver'`` or ``None``. See :ref:`multiprocessing-start-methods`. @@ -1373,9 +1380,8 @@ object -- see :ref:`multiprocessing-managers`. A barrier object: a clone of :class:`threading.Barrier`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. .. versionadded:: 3.3 @@ -1384,9 +1390,8 @@ object -- see :ref:`multiprocessing-managers`. A bounded semaphore object: a close analog of :class:`threading.BoundedSemaphore`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. A solitary difference from its close analog exists: its ``acquire`` method's first argument is named *block*, as is consistent with :meth:`Lock.acquire`. @@ -1408,9 +1413,8 @@ object -- see :ref:`multiprocessing-managers`. If *lock* is specified then it should be a :class:`Lock` or :class:`RLock` object from :mod:`multiprocessing`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. .. versionchanged:: 3.3 The :meth:`~threading.Condition.wait_for` method was added. @@ -1419,9 +1423,8 @@ object -- see :ref:`multiprocessing-managers`. A clone of :class:`threading.Event`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. .. class:: Lock() @@ -1437,9 +1440,8 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.Lock`` initialized with a default context. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. :class:`Lock` supports the :term:`context manager` protocol and thus may be used in :keyword:`with` statements. @@ -1498,9 +1500,8 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.RLock`` initialized with a default context. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. :class:`RLock` supports the :term:`context manager` protocol and thus may be used in :keyword:`with` statements. @@ -1561,9 +1562,8 @@ object -- see :ref:`multiprocessing-managers`. A semaphore object: a close analog of :class:`threading.Semaphore`. - If the global start method has not been set, calling this function will - have the side effect of setting the current global start method. - See the :func:`get_context` function. + Calling this may set the global start method. See + :ref:`global-start-method` for more details. A solitary difference from its close analog exists: its ``acquire`` method's first argument is named *block*, as is consistent with :meth:`Lock.acquire`. @@ -1714,9 +1714,8 @@ processes. "process-safe". *ctx* is a context object, or ``None`` (use the current context). If ``None``, - calling this function will have the side effect of setting the current global - start method if it has not been set already. See the :func:`get_context` - function. + calling this may set the global start method. See + :ref:`global-start-method` for more details. Note that *lock* and *ctx* are keyword-only parameters. @@ -1734,9 +1733,8 @@ processes. "process-safe". *ctx* is a context object, or ``None`` (use the current context). If ``None``, - calling this function will have the side effect of setting the current global - start method if it has not been set already. See the :func:`get_context` - function. + calling this may set the global start method. See + :ref:`global-start-method` for more details. Note that *lock* and *ctx* are keyword-only parameters. @@ -1752,9 +1750,8 @@ processes. :class:`multiprocessing.RLock` object is created automatically. *ctx* is a context object, or ``None`` (use the current context). If ``None``, - calling this function will have the side effect of setting the current global - start method if it has not been set already. See the :func:`get_context` - function. + calling this may set the global start method. See + :ref:`global-start-method` for more details. A synchronized wrapper will have two methods in addition to those of the object it wraps: :meth:`get_obj` returns the wrapped object and @@ -1874,9 +1871,8 @@ their parent process exits. The manager classes are defined in the ``'xmlrpclib'`` (use :mod:`xmlrpc.client` serialization). *ctx* is a context object, or ``None`` (use the current context). If ``None``, - calling this function will have the side effect of setting the current global - start method if it has not been set already. See the :func:`get_context` - function. + calling this may set the global start method. See + :ref:`global-start-method` for more details. *shutdown_timeout* is a timeout in seconds used to wait until the process used by the manager completes in the :meth:`shutdown` method. If the From de6192674071e0f7ee049ef95c6d7be2c64bab46 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 00:59:33 +0900 Subject: [PATCH 07/11] calling -> instantiating --- Doc/library/multiprocessing.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index e1ab1ece7c203a..a40b02f2d90716 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -878,7 +878,7 @@ For an example of the usage of queues for interprocess communication see locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. The usual :exc:`queue.Empty` and :exc:`queue.Full` exceptions from the @@ -991,7 +991,7 @@ For an example of the usage of queues for interprocess communication see It is a simplified :class:`Queue` type, very close to a locked :class:`Pipe`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. .. method:: close() @@ -1024,7 +1024,7 @@ For an example of the usage of queues for interprocess communication see :class:`JoinableQueue`, a :class:`Queue` subclass, is a queue which additionally has :meth:`task_done` and :meth:`join` methods. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. .. method:: task_done() @@ -1380,7 +1380,7 @@ object -- see :ref:`multiprocessing-managers`. A barrier object: a clone of :class:`threading.Barrier`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. .. versionadded:: 3.3 @@ -1390,7 +1390,7 @@ object -- see :ref:`multiprocessing-managers`. A bounded semaphore object: a close analog of :class:`threading.BoundedSemaphore`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. A solitary difference from its close analog exists: its ``acquire`` method's @@ -1413,7 +1413,7 @@ object -- see :ref:`multiprocessing-managers`. If *lock* is specified then it should be a :class:`Lock` or :class:`RLock` object from :mod:`multiprocessing`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. .. versionchanged:: 3.3 @@ -1423,7 +1423,7 @@ object -- see :ref:`multiprocessing-managers`. A clone of :class:`threading.Event`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. .. class:: Lock() @@ -1440,7 +1440,7 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.Lock`` initialized with a default context. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. :class:`Lock` supports the :term:`context manager` protocol and thus may be @@ -1500,7 +1500,7 @@ object -- see :ref:`multiprocessing-managers`. instance of ``multiprocessing.synchronize.RLock`` initialized with a default context. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. :class:`RLock` supports the :term:`context manager` protocol and thus may be @@ -1562,7 +1562,7 @@ object -- see :ref:`multiprocessing-managers`. A semaphore object: a close analog of :class:`threading.Semaphore`. - Calling this may set the global start method. See + Instantiating this class may set the global start method. See :ref:`global-start-method` for more details. A solitary difference from its close analog exists: its ``acquire`` method's From 982c7c258c5e6195113fa63b914618cc2c72ddf2 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 20:22:35 +0900 Subject: [PATCH 08/11] Update Doc/library/multiprocessing.rst Co-authored-by: Carol Willing --- Doc/library/multiprocessing.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index a40b02f2d90716..ce93b5c8fcbf54 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -516,11 +516,13 @@ The :mod:`multiprocessing` package mostly replicates the API of the Global start method ^^^^^^^^^^^^^^^^^^^ -Calling some functions or methods, or creating some objects, will implicitly -set the global start method to the system's default if it is not already -set. This can only be done once. Therefore, if you need to change the -start method, you must do so before calling these functions or methods, or -creating these objects. +Python supports several ways to create and initialize a process. The global start method sets the default mechanism for creating a process. + +Several multiprocessing functions and methods, as well as creating some objects, will implicitly +set the global start method to the system's default, if the global start method is not already +set. The global start method can only be done once. If you need to change the +start method from the system default, you must proactively set the global start method +before calling functions or methods, or creating these objects. :class:`Process` and exceptions From c85562f21af66252990c2f1eb1651adb599a6877 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 22:25:37 +0900 Subject: [PATCH 09/11] Apply suggestions from code review Co-authored-by: R Chintan Meher --- Doc/library/multiprocessing.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index ce93b5c8fcbf54..39d9261ca3668c 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -518,9 +518,9 @@ Global start method Python supports several ways to create and initialize a process. The global start method sets the default mechanism for creating a process. -Several multiprocessing functions and methods, as well as creating some objects, will implicitly -set the global start method to the system's default, if the global start method is not already -set. The global start method can only be done once. If you need to change the +Several multiprocessing functions and methods that may also instantiate +certain objects will implicitly set the global start method to the system's default, +if it hasn’t been set already. The global start method can only be set once. If you need to change the start method from the system default, you must proactively set the global start method before calling functions or methods, or creating these objects. @@ -1141,7 +1141,7 @@ Miscellaneous :mod:`multiprocessing` module. If *method* is ``None`` then the default context is returned. Note that if - the global start method has not been set, this will set it. + the global start method has not been set, this will set it to the system default See :ref:`global-start-method` for more details. Otherwise *method* should be ``'fork'``, ``'spawn'``, ``'forkserver'``. :exc:`ValueError` is raised if the specified @@ -1153,7 +1153,7 @@ Miscellaneous Return the name of start method used for starting processes. - If the start method is not set and *allow_none* is ``False``, the start + If the global start method is not set and *allow_none* is ``False``, the global start method is set to the default, and its name is returned. See :ref:`global-start-method` for more details. From 8a9ae53102d6ae5f39d7c41f6ff019a213a03933 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 22:34:27 +0900 Subject: [PATCH 10/11] Update Doc/library/multiprocessing.rst Co-authored-by: R Chintan Meher --- Doc/library/multiprocessing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 39d9261ca3668c..cc8c66ac803b62 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -519,7 +519,7 @@ Global start method Python supports several ways to create and initialize a process. The global start method sets the default mechanism for creating a process. Several multiprocessing functions and methods that may also instantiate -certain objects will implicitly set the global start method to the system's default, +certain objects will implicitly set the global start method to the system's default, if it hasn’t been set already. The global start method can only be set once. If you need to change the start method from the system default, you must proactively set the global start method before calling functions or methods, or creating these objects. From a62a4fe1e082b82ed22f7ffd97e2abaa645b2671 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 23:30:35 +0900 Subject: [PATCH 11/11] Fix line-break --- Doc/library/multiprocessing.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index cc8c66ac803b62..bcf0beba5f0c7e 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -516,13 +516,15 @@ The :mod:`multiprocessing` package mostly replicates the API of the Global start method ^^^^^^^^^^^^^^^^^^^ -Python supports several ways to create and initialize a process. The global start method sets the default mechanism for creating a process. +Python supports several ways to create and initialize a process. +The global start method sets the default mechanism for creating a process. Several multiprocessing functions and methods that may also instantiate certain objects will implicitly set the global start method to the system's default, -if it hasn’t been set already. The global start method can only be set once. If you need to change the -start method from the system default, you must proactively set the global start method -before calling functions or methods, or creating these objects. +if it hasn’t been set already. The global start method can only be set once. +If you need to change the start method from the system default, you must +proactively set the global start method before calling functions or methods, +or creating these objects. :class:`Process` and exceptions