fix up the multiprocessing docs a little

This commit is contained in:
Benjamin Peterson 2008-08-20 14:07:59 +00:00
parent 838c79f472
commit 73641d7eb4

View file

@ -250,7 +250,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
The constructor should always be called with keyword arguments. *group* The constructor should always be called with keyword arguments. *group*
should always be ``None``; it exists solely for compatibility with should always be ``None``; it exists solely for compatibility with
:class:`~threading.Thread`. *target* is the callable object to be invoked by :class:`threading.Thread`. *target* is the callable object to be invoked by
the :meth:`run()` method. It defaults to ``None``, meaning nothing is the :meth:`run()` method. It defaults to ``None``, meaning nothing is
called. *name* is the process name. By default, a unique name is constructed called. *name* is the process name. By default, a unique name is constructed
of the form 'Process-N\ :sub:`1`:N\ :sub:`2`:...:N\ :sub:`k`' where N\ of the form 'Process-N\ :sub:`1`:N\ :sub:`2`:...:N\ :sub:`k`' where N\
@ -292,13 +292,9 @@ The :mod:`multiprocessing` package mostly replicates the API of the
A process cannot join itself because this would cause a deadlock. It is A process cannot join itself because this would cause a deadlock. It is
an error to attempt to join a process before it has been started. an error to attempt to join a process before it has been started.
.. attribute:: Process.name .. attribute:: name
Return the process's name. The process's name.
.. attribute:: Process.name = name
Set the process's name.
The name is a string used for identification purposes only. It has no The name is a string used for identification purposes only. It has no
semantics. Multiple processes may be given the same name. The initial semantics. Multiple processes may be given the same name. The initial
@ -311,14 +307,10 @@ The :mod:`multiprocessing` package mostly replicates the API of the
Roughly, a process object is alive from the moment the :meth:`start` Roughly, a process object is alive from the moment the :meth:`start`
method returns until the child process terminates. method returns until the child process terminates.
.. attribute:: Process.daemon .. attribute:: daemon
Return the process's daemon flag., this is a boolean. The process's daemon flag, a Boolean value. This must be called before
:meth:`start` is called.
.. attribute:: Process.daemon = daemonic
Set the process's daemon flag to the Boolean value *daemonic*. This must
be called before :meth:`start` is called.
The initial value is inherited from the creating process. The initial value is inherited from the creating process.
@ -331,34 +323,30 @@ The :mod:`multiprocessing` package mostly replicates the API of the
In addition process objects also support the following methods: In addition process objects also support the following methods:
.. attribute:: Process.pid .. attribute:: pid
Return the process ID. Before the process is spawned, this will be Return the process ID. Before the process is spawned, this will be
``None``. ``None``.
.. attribute:: Process.exitcode .. attribute:: exitcode
Return the child's exit code. This will be ``None`` if the process has The child's exit code. This will be ``None`` if the process has not yet
not yet terminated. A negative value *-N* indicates that the child was terminated. A negative value *-N* indicates that the child was terminated
terminated by signal *N*. by signal *N*.
.. attribute:: Process.authkey .. attribute:: authkey
Return 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.random`.
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 authentication key of its parent process, although this may be changed by
using :attr:`Process.authkey` below. setting :attr:`authkey` to another byte string.
See :ref:`multiprocessing-auth-keys`. See :ref:`multiprocessing-auth-keys`.
.. attribute:: Process.authkey = authkey
Set the process's authentication key which must be a byte string.
.. method:: terminate() .. method:: terminate()
Terminate the process. On Unix this is done using the ``SIGTERM`` signal; Terminate the process. On Unix this is done using the ``SIGTERM`` signal;
@ -377,8 +365,8 @@ The :mod:`multiprocessing` package mostly replicates the API of the
cause other processes to deadlock. cause other processes to deadlock.
Note that the :meth:`start`, :meth:`join`, :meth:`is_alive` and Note that the :meth:`start`, :meth:`join`, :meth:`is_alive` and
:meth:`get_exit_code` methods should only be called by the process that :attr:`exit_code` methods should only be called by the process that created
created the process object. the process object.
Example usage of some of the methods of :class:`Process`:: Example usage of some of the methods of :class:`Process`::
@ -392,7 +380,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
>>> p.terminate() >>> p.terminate()
>>> print p, p.is_alive() >>> print p, p.is_alive()
<Process(Process-1, stopped[SIGTERM])> False <Process(Process-1, stopped[SIGTERM])> False
>>> p.get_exit_code() == -signal.SIGTERM >>> p.exitcode == -signal.SIGTERM
True True
@ -1077,7 +1065,7 @@ their parent process exits. The manager classes are defined in the
*authkey* is the authentication key which will be used to check the validity *authkey* is the authentication key which will be used to check the validity
of incoming connections to the server process. If *authkey* is ``None`` then of incoming connections to the server process. If *authkey* is ``None`` then
``current_process().get_auth_key()``. Otherwise *authkey* is used and it ``current_process().authkey``. Otherwise *authkey* is used and it
must be a string. must be a string.
.. method:: start() .. method:: start()
@ -1601,7 +1589,7 @@ authentication* using the :mod:`hmac` module.
If *authentication* is ``True`` or *authkey* is a string then digest If *authentication* is ``True`` or *authkey* is a string then digest
authentication is used. The key used for authentication will be either authentication is used. The key used for authentication will be either
*authkey* or ``current_process().get_auth_key()`` if *authkey* is ``None``. *authkey* or ``current_process().authkey)`` if *authkey* is ``None``.
If authentication fails then :exc:`AuthenticationError` is raised. See If authentication fails then :exc:`AuthenticationError` is raised. See
:ref:`multiprocessing-auth-keys`. :ref:`multiprocessing-auth-keys`.
@ -1634,7 +1622,7 @@ authentication* using the :mod:`hmac` module.
otherwise it must be *None*. otherwise it must be *None*.
If *authkey* is ``None`` and *authenticate* is ``True`` then If *authkey* is ``None`` and *authenticate* is ``True`` then
``current_process().get_auth_key()`` is used as the authentication key. If ``current_process().authkey`` is used as the authentication key. If
*authkey* is ``None`` and *authentication* is ``False`` then no *authkey* is ``None`` and *authentication* is ``False`` then no
authentication is done. If authentication fails then authentication is done. If authentication fails then
:exc:`AuthenticationError` is raised. See :ref:`multiprocessing-auth-keys`. :exc:`AuthenticationError` is raised. See :ref:`multiprocessing-auth-keys`.
@ -1750,7 +1738,7 @@ authentication key. (Demonstrating that both ends are using the same key does
**not** involve sending the key over the connection.) **not** involve sending the key over the connection.)
If authentication is requested but do authentication key is specified then the If authentication is requested but do authentication key is specified then the
return value of ``current_process().get_auth_key`` is used (see return value of ``current_process().authkey`` is used (see
:class:`~multiprocessing.Process`). This value will automatically inherited by :class:`~multiprocessing.Process`). This value will automatically inherited by
any :class:`~multiprocessing.Process` object that the current process creates. any :class:`~multiprocessing.Process` object that the current process creates.
This means that (by default) all processes of a multi-process program will share This means that (by default) all processes of a multi-process program will share