Commit b986b607 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #18757: Improved cross-references in the concurrent package.

parent 309de7d1
...@@ -382,7 +382,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the ...@@ -382,7 +382,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
Unix daemons or services, they are normal processes that will be Unix daemons or services, they are normal processes that will be
terminated (and not joined) if non-daemonic processes have exited. terminated (and not joined) if non-daemonic processes have exited.
In addition to the :class:`Threading.Thread` API, :class:`Process` objects In addition to the :class:`threading.Thread` API, :class:`Process` objects
also support the following attributes and methods: also support the following attributes and methods:
.. attribute:: pid .. attribute:: pid
...@@ -401,7 +401,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the ...@@ -401,7 +401,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
The process's authentication key (a byte string). The process's authentication key (a byte string).
When :mod:`multiprocessing` is initialized the main process is assigned a When :mod:`multiprocessing` is initialized the main process is assigned a
random string using :func:`os.random`. random string using :func:`os.urandom`.
When a :class:`Process` object is created, it will inherit the When a :class:`Process` object is created, it will inherit the
authentication key of its parent process, although this may be changed by authentication key of its parent process, although this may be changed by
...@@ -518,7 +518,8 @@ Note that one can also create a shared queue by using a manager object -- see ...@@ -518,7 +518,8 @@ Note that one can also create a shared queue by using a manager object -- see
.. warning:: .. warning::
As mentioned above, if a child process has put items on a queue (and it has As mentioned above, if a child process has put items on a queue (and it has
not used :meth:`JoinableQueue.cancel_join_thread`), then that process will not used :meth:`JoinableQueue.cancel_join_thread
<multiprocessing.Queue.cancel_join_thread>`), then that process will
not terminate until all buffered items have been flushed to the pipe. not terminate until all buffered items have been flushed to the pipe.
This means that if you try joining that process you may get a deadlock unless This means that if you try joining that process you may get a deadlock unless
...@@ -667,7 +668,7 @@ For an example of the usage of queues for interprocess communication see ...@@ -667,7 +668,7 @@ For an example of the usage of queues for interprocess communication see
call to :meth:`task_done` tells the queue that the processing on the task call to :meth:`task_done` tells the queue that the processing on the task
is complete. is complete.
If a :meth:`~Queue.join` is currently blocking, it will resume when all If a :meth:`~Queue.Queue.join` is currently blocking, it will resume when all
items have been processed (meaning that a :meth:`task_done` call was items have been processed (meaning that a :meth:`task_done` call was
received for every item that had been :meth:`~Queue.put` into the queue). received for every item that had been :meth:`~Queue.put` into the queue).
...@@ -683,7 +684,7 @@ For an example of the usage of queues for interprocess communication see ...@@ -683,7 +684,7 @@ For an example of the usage of queues for interprocess communication see
queue. The count goes down whenever a consumer thread calls queue. The count goes down whenever a consumer thread calls
:meth:`task_done` to indicate that the item was retrieved and all work on :meth:`task_done` to indicate that the item was retrieved and all work on
it is complete. When the count of unfinished tasks drops to zero, it is complete. When the count of unfinished tasks drops to zero,
:meth:`~Queue.join` unblocks. :meth:`~Queue.Queue.join` unblocks.
Miscellaneous Miscellaneous
...@@ -1049,8 +1050,9 @@ processes. ...@@ -1049,8 +1050,9 @@ processes.
array. array.
If *lock* is ``True`` (the default) then a new lock object is created to If *lock* is ``True`` (the default) then a new lock object is created to
synchronize access to the value. If *lock* is a :class:`Lock` or synchronize access to the value. If *lock* is a
:class:`RLock` object then that will be used to synchronize access to the :class:`~multiprocessing.Lock` or :class:`~multiprocessing.RLock` object
then that will be used to synchronize access to the
value. If *lock* is ``False`` then access to the returned object will not be value. If *lock* is ``False`` then access to the returned object will not be
automatically protected by a lock, so it will not necessarily be automatically protected by a lock, so it will not necessarily be
"process-safe". "process-safe".
...@@ -1064,8 +1066,8 @@ processes. ...@@ -1064,8 +1066,8 @@ processes.
object. object.
If *lock* is ``True`` (the default) then a new lock object is created to If *lock* is ``True`` (the default) then a new lock object is created to
synchronize access to the value. If *lock* is a :class:`Lock` or synchronize access to the value. If *lock* is a :class:`~multiprocessing.Lock` or
:class:`RLock` object then that will be used to synchronize access to the :class:`~multiprocessing.RLock` object then that will be used to synchronize access to the
value. If *lock* is ``False`` then access to the returned object will not be value. If *lock* is ``False`` then access to the returned object will not be
automatically protected by a lock, so it will not necessarily be automatically protected by a lock, so it will not necessarily be
"process-safe". "process-safe".
...@@ -1247,8 +1249,8 @@ their parent process exits. The manager classes are defined in the ...@@ -1247,8 +1249,8 @@ their parent process exits. The manager classes are defined in the
:attr:`proxytype._exposed_` is used instead if it exists.) In the case :attr:`proxytype._exposed_` is used instead if it exists.) In the case
where no exposed list is specified, all "public methods" of the shared where no exposed list is specified, all "public methods" of the shared
object will be accessible. (Here a "public method" means any attribute object will be accessible. (Here a "public method" means any attribute
which has a :meth:`__call__` method and whose name does not begin with which has a :meth:`~object.__call__` method and whose name does not begin
``'_'``.) with ``'_'``.)
*method_to_typeid* is a mapping used to specify the return type of those *method_to_typeid* is a mapping used to specify the return type of those
exposed methods which should return a proxy. It maps method names to exposed methods which should return a proxy. It maps method names to
...@@ -1758,7 +1760,8 @@ Listeners and Clients ...@@ -1758,7 +1760,8 @@ Listeners and Clients
:synopsis: API for dealing with sockets. :synopsis: API for dealing with sockets.
Usually message passing between processes is done using queues or by using Usually message passing between processes is done using queues or by using
:class:`Connection` objects returned by :func:`Pipe`. :class:`~multiprocessing.Connection` objects returned by
:func:`~multiprocessing.Pipe`.
However, the :mod:`multiprocessing.connection` module allows some extra However, the :mod:`multiprocessing.connection` module allows some extra
flexibility. It basically gives a high level message oriented API for dealing flexibility. It basically gives a high level message oriented API for dealing
...@@ -1824,7 +1827,8 @@ authentication* using the :mod:`hmac` module. ...@@ -1824,7 +1827,8 @@ authentication* using the :mod:`hmac` module.
private temporary directory created using :func:`tempfile.mkstemp`. private temporary directory created using :func:`tempfile.mkstemp`.
If the listener object uses a socket then *backlog* (1 by default) is passed If the listener object uses a socket then *backlog* (1 by default) is passed
to the :meth:`listen` method of the socket once it has been bound. to the :meth:`~socket.socket.listen` method of the socket once it has been
bound.
If *authenticate* is ``True`` (``False`` by default) or *authkey* is not If *authenticate* is ``True`` (``False`` by default) or *authkey* is not
``None`` then digest authentication is used. ``None`` then digest authentication is used.
...@@ -1841,8 +1845,9 @@ authentication* using the :mod:`hmac` module. ...@@ -1841,8 +1845,9 @@ authentication* using the :mod:`hmac` module.
.. method:: accept() .. method:: accept()
Accept a connection on the bound socket or named pipe of the listener Accept a connection on the bound socket or named pipe of the listener
object and return a :class:`Connection` object. If authentication is object and return a :class:`~multiprocessing.Connection` object. If
attempted and fails, then :exc:`AuthenticationError` is raised. authentication is attempted and fails, then
:exc:`~multiprocessing.AuthenticationError` is raised.
.. method:: close() .. method:: close()
...@@ -1938,7 +1943,8 @@ an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. ...@@ -1938,7 +1943,8 @@ an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address.
Authentication keys Authentication keys
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
When one uses :meth:`Connection.recv`, the data received is automatically When one uses :meth:`Connection.recv <multiprocessing.Connection.recv>`, the
data received is automatically
unpickled. Unfortunately unpickling data from an untrusted source is a security unpickled. Unfortunately unpickling data from an untrusted source is a security
risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module
to provide digest authentication. to provide digest authentication.
...@@ -2087,9 +2093,10 @@ Joining zombie processes ...@@ -2087,9 +2093,10 @@ Joining zombie processes
On Unix when a process finishes but has not been joined it becomes a zombie. On Unix when a process finishes but has not been joined it becomes a zombie.
There should never be very many because each time a new process starts (or There should never be very many because each time a new process starts (or
:func:`active_children` is called) all completed processes which have not :func:`~multiprocessing.active_children` is called) all completed processes
yet been joined will be joined. Also calling a finished process's which have not yet been joined will be joined. Also calling a finished
:meth:`Process.is_alive` will join the process. Even so it is probably good process's :meth:`Process.is_alive <multiprocessing.Process.is_alive>` will
join the process. Even so it is probably good
practice to explicitly join all the processes that you start. practice to explicitly join all the processes that you start.
Better to inherit than pickle/unpickle Better to inherit than pickle/unpickle
...@@ -2102,13 +2109,15 @@ Better to inherit than pickle/unpickle ...@@ -2102,13 +2109,15 @@ Better to inherit than pickle/unpickle
Avoid terminating processes Avoid terminating processes
Using the :meth:`Process.terminate` method to stop a process is liable to Using the :meth:`Process.terminate <multiprocessing.Process.terminate>`
method to stop a process is liable to
cause any shared resources (such as locks, semaphores, pipes and queues) cause any shared resources (such as locks, semaphores, pipes and queues)
currently being used by the process to become broken or unavailable to other currently being used by the process to become broken or unavailable to other
processes. processes.
Therefore it is probably best to only consider using Therefore it is probably best to only consider using
:meth:`Process.terminate` on processes which never use any shared resources. :meth:`Process.terminate <multiprocessing.Process.terminate>` on processes
which never use any shared resources.
Joining processes that use queues Joining processes that use queues
...@@ -2192,7 +2201,7 @@ Beware of replacing :data:`sys.stdin` with a "file like object" ...@@ -2192,7 +2201,7 @@ Beware of replacing :data:`sys.stdin` with a "file like object"
resulting in a bad file descriptor error, but introduces a potential danger resulting in a bad file descriptor error, but introduces a potential danger
to applications which replace :func:`sys.stdin` with a "file-like object" to applications which replace :func:`sys.stdin` with a "file-like object"
with output buffering. This danger is that if multiple processes call with output buffering. This danger is that if multiple processes call
:func:`close()` on this file-like object, it could result in the same :meth:`~io.IOBase.close()` on this file-like object, it could result in the same
data being flushed to the object multiple times, resulting in corruption. data being flushed to the object multiple times, resulting in corruption.
If you write a file-like object and implement your own caching, you can If you write a file-like object and implement your own caching, you can
...@@ -2221,14 +2230,16 @@ More picklability ...@@ -2221,14 +2230,16 @@ More picklability
as the ``target`` argument on Windows --- just define a function and use as the ``target`` argument on Windows --- just define a function and use
that instead. that instead.
Also, if you subclass :class:`Process` then make sure that instances will be Also, if you subclass :class:`~multiprocessing.Process` then make sure that
picklable when the :meth:`Process.start` method is called. instances will be picklable when the :meth:`Process.start
<multiprocessing.Process.start>` method is called.
Global variables Global variables
Bear in mind that if code run in a child process tries to access a global Bear in mind that if code run in a child process tries to access a global
variable, then the value it sees (if any) may not be the same as the value variable, then the value it sees (if any) may not be the same as the value
in the parent process at the time that :meth:`Process.start` was called. in the parent process at the time that :meth:`Process.start
<multiprocessing.Process.start>` was called.
However, global variables which are just module level constants cause no However, global variables which are just module level constants cause no
problems. problems.
...@@ -2283,7 +2294,7 @@ Demonstration of how to create and use customized managers and proxies: ...@@ -2283,7 +2294,7 @@ Demonstration of how to create and use customized managers and proxies:
.. literalinclude:: ../includes/mp_newtype.py .. literalinclude:: ../includes/mp_newtype.py
Using :class:`Pool`: Using :class:`~multiprocessing.pool.Pool`:
.. literalinclude:: ../includes/mp_pool.py .. literalinclude:: ../includes/mp_pool.py
......
...@@ -60,13 +60,15 @@ The :mod:`Queue` module defines the following classes and exceptions: ...@@ -60,13 +60,15 @@ The :mod:`Queue` module defines the following classes and exceptions:
.. exception:: Empty .. exception:: Empty
Exception raised when non-blocking :meth:`get` (or :meth:`get_nowait`) is called Exception raised when non-blocking :meth:`~Queue.get` (or
:meth:`~Queue.get_nowait`) is called
on a :class:`Queue` object which is empty. on a :class:`Queue` object which is empty.
.. exception:: Full .. exception:: Full
Exception raised when non-blocking :meth:`put` (or :meth:`put_nowait`) is called Exception raised when non-blocking :meth:`~Queue.put` (or
:meth:`~Queue.put_nowait`) is called
on a :class:`Queue` object which is full. on a :class:`Queue` object which is full.
.. seealso:: .. seealso::
......
...@@ -63,7 +63,7 @@ The module defines the following: ...@@ -63,7 +63,7 @@ The module defines the following:
This is a straightforward interface to the Unix :c:func:`select` system call. This is a straightforward interface to the Unix :c:func:`select` system call.
The first three arguments are sequences of 'waitable objects': either The first three arguments are sequences of 'waitable objects': either
integers representing file descriptors or objects with a parameterless method integers representing file descriptors or objects with a parameterless method
named :meth:`fileno` returning such an integer: named :meth:`~io.IOBase.fileno` returning such an integer:
* *rlist*: wait until ready for reading * *rlist*: wait until ready for reading
* *wlist*: wait until ready for writing * *wlist*: wait until ready for writing
...@@ -88,8 +88,8 @@ The module defines the following: ...@@ -88,8 +88,8 @@ The module defines the following:
Among the acceptable object types in the sequences are Python file objects (e.g. Among the acceptable object types in the sequences are Python file objects (e.g.
``sys.stdin``, or objects returned by :func:`open` or :func:`os.popen`), socket ``sys.stdin``, or objects returned by :func:`open` or :func:`os.popen`), socket
objects returned by :func:`socket.socket`. You may also define a :dfn:`wrapper` objects returned by :func:`socket.socket`. You may also define a :dfn:`wrapper`
class yourself, as long as it has an appropriate :meth:`fileno` method (that class yourself, as long as it has an appropriate :meth:`~io.IOBase.fileno`
really returns a file descriptor, not just a random integer). method (that really returns a file descriptor, not just a random integer).
.. note:: .. note::
...@@ -207,10 +207,10 @@ linearly scanned again. :c:func:`select` is O(highest file descriptor), while ...@@ -207,10 +207,10 @@ linearly scanned again. :c:func:`select` is O(highest file descriptor), while
.. method:: poll.register(fd[, eventmask]) .. method:: poll.register(fd[, eventmask])
Register a file descriptor with the polling object. Future calls to the Register a file descriptor with the polling object. Future calls to the
:meth:`poll` method will then check whether the file descriptor has any pending :meth:`poll` method will then check whether the file descriptor has any
I/O events. *fd* can be either an integer, or an object with a :meth:`fileno` pending I/O events. *fd* can be either an integer, or an object with a
method that returns an integer. File objects implement :meth:`fileno`, so they :meth:`~io.IOBase.fileno` method that returns an integer. File objects
can also be used as the argument. implement :meth:`!fileno`, so they can also be used as the argument.
*eventmask* is an optional bitmask describing the type of events you want to *eventmask* is an optional bitmask describing the type of events you want to
check for, and can be a combination of the constants :const:`POLLIN`, check for, and can be a combination of the constants :const:`POLLIN`,
...@@ -251,7 +251,7 @@ linearly scanned again. :c:func:`select` is O(highest file descriptor), while ...@@ -251,7 +251,7 @@ linearly scanned again. :c:func:`select` is O(highest file descriptor), while
Remove a file descriptor being tracked by a polling object. Just like the Remove a file descriptor being tracked by a polling object. Just like the
:meth:`register` method, *fd* can be an integer or an object with a :meth:`register` method, *fd* can be an integer or an object with a
:meth:`fileno` method that returns an integer. :meth:`~io.IOBase.fileno` method that returns an integer.
Attempting to remove a file descriptor that was never registered causes a Attempting to remove a file descriptor that was never registered causes a
:exc:`KeyError` exception to be raised. :exc:`KeyError` exception to be raised.
......
...@@ -74,7 +74,7 @@ use cases, the underlying :class:`Popen` interface can be used directly. ...@@ -74,7 +74,7 @@ use cases, the underlying :class:`Popen` interface can be used directly.
Run command with arguments. Wait for command to complete. If the return Run command with arguments. Wait for command to complete. If the return
code was zero then return, otherwise raise :exc:`CalledProcessError`. The code was zero then return, otherwise raise :exc:`CalledProcessError`. The
:exc:`CalledProcessError` object will have the return code in the :exc:`CalledProcessError` object will have the return code in the
:attr:`returncode` attribute. :attr:`~CalledProcessError.returncode` attribute.
The arguments shown above are merely the most common ones, described below The arguments shown above are merely the most common ones, described below
in :ref:`frequently-used-arguments` (hence the slightly odd notation in in :ref:`frequently-used-arguments` (hence the slightly odd notation in
...@@ -114,8 +114,8 @@ use cases, the underlying :class:`Popen` interface can be used directly. ...@@ -114,8 +114,8 @@ use cases, the underlying :class:`Popen` interface can be used directly.
If the return code was non-zero it raises a :exc:`CalledProcessError`. The If the return code was non-zero it raises a :exc:`CalledProcessError`. The
:exc:`CalledProcessError` object will have the return code in the :exc:`CalledProcessError` object will have the return code in the
:attr:`returncode` attribute and any output in the :attr:`output` :attr:`~CalledProcessError.returncode` attribute and any output in the
attribute. :attr:`~CalledProcessError.output` attribute.
The arguments shown above are merely the most common ones, described below The arguments shown above are merely the most common ones, described below
in :ref:`frequently-used-arguments` (hence the slightly odd notation in in :ref:`frequently-used-arguments` (hence the slightly odd notation in
...@@ -462,14 +462,14 @@ Instances of the :class:`Popen` class have the following methods: ...@@ -462,14 +462,14 @@ Instances of the :class:`Popen` class have the following methods:
.. method:: Popen.poll() .. method:: Popen.poll()
Check if child process has terminated. Set and return :attr:`returncode` Check if child process has terminated. Set and return
attribute. :attr:`~Popen.returncode` attribute.
.. method:: Popen.wait() .. method:: Popen.wait()
Wait for child process to terminate. Set and return :attr:`returncode` Wait for child process to terminate. Set and return
attribute. :attr:`~Popen.returncode` attribute.
.. warning:: .. warning::
...@@ -695,8 +695,8 @@ In this section, "a becomes b" means that b can be used as a replacement for a. ...@@ -695,8 +695,8 @@ In this section, "a becomes b" means that b can be used as a replacement for a.
In addition, the replacements using :func:`check_output` will fail with a In addition, the replacements using :func:`check_output` will fail with a
:exc:`CalledProcessError` if the requested operation produces a non-zero :exc:`CalledProcessError` if the requested operation produces a non-zero
return code. The output is still available as the ``output`` attribute of return code. The output is still available as the
the raised exception. :attr:`~CalledProcessError.output` attribute of the raised exception.
In the following examples, we assume that the relevant functions have already In the following examples, we assume that the relevant functions have already
been imported from the :mod:`subprocess` module. been imported from the :mod:`subprocess` module.
......
...@@ -167,7 +167,7 @@ This module defines the following functions and objects: ...@@ -167,7 +167,7 @@ This module defines the following functions and objects:
Set a trace function for all threads started from the :mod:`threading` module. Set a trace function for all threads started from the :mod:`threading` module.
The *func* will be passed to :func:`sys.settrace` for each thread, before its The *func* will be passed to :func:`sys.settrace` for each thread, before its
:meth:`run` method is called. :meth:`~Thread.run` method is called.
.. versionadded:: 2.3 .. versionadded:: 2.3
...@@ -178,7 +178,7 @@ This module defines the following functions and objects: ...@@ -178,7 +178,7 @@ This module defines the following functions and objects:
Set a profile function for all threads started from the :mod:`threading` module. Set a profile function for all threads started from the :mod:`threading` module.
The *func* will be passed to :func:`sys.setprofile` for each thread, before its The *func* will be passed to :func:`sys.setprofile` for each thread, before its
:meth:`run` method is called. :meth:`~Thread.run` method is called.
.. versionadded:: 2.3 .. versionadded:: 2.3
...@@ -742,10 +742,11 @@ This class represents an action that should be run only after a certain amount ...@@ -742,10 +742,11 @@ This class represents an action that should be run only after a certain amount
of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread` of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread`
and as such also functions as an example of creating custom threads. and as such also functions as an example of creating custom threads.
Timers are started, as with threads, by calling their :meth:`start` method. The Timers are started, as with threads, by calling their :meth:`~Timer.start`
timer can be stopped (before its action has begun) by calling the :meth:`cancel` method. The timer can be stopped (before its action has begun) by calling the
method. The interval the timer will wait before executing its action may not be :meth:`~Timer.cancel` method. The interval the timer will wait before
exactly the same as the interval specified by the user. executing its action may not be exactly the same as the interval specified by
the user.
For example:: For example::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment