~pythoneers/ubuntu/lucid/python2.6/ltsppa

« back to all changes in this revision

Viewing changes to Doc/library/multiprocessing.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100311133019-sonignhpjsu6ld0x
Tags: 2.6.5~rc2-0ubuntu1
Python 2.6.5 release candidate 2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
374
374
 
375
375
      Note that a daemonic process is not allowed to create child processes.
376
376
      Otherwise a daemonic process would leave its children orphaned if it gets
377
 
      terminated when its parent process exits.
 
377
      terminated when its parent process exits. Additionally, these are **not**
 
378
      Unix daemons or services, they are normal processes that will be
 
379
      terminated (and not joined) if non-dameonic processes have exited.
378
380
 
379
381
   In addition to the  :class:`Threading.Thread` API, :class:`Process` objects
380
382
   also support the following attributes and methods:
686
688
 
687
689
.. function:: set_executable()
688
690
 
689
 
   Sets the path of the python interpreter to use when starting a child process.
 
691
   Sets the path of the Python interpreter to use when starting a child process.
690
692
   (By default :data:`sys.executable` is used).  Embedders will probably need to
691
693
   do some thing like ::
692
694
 
1538
1540
 
1539
1541
   .. method:: apply(func[, args[, kwds]])
1540
1542
 
1541
 
      Equivalent of the :func:`apply` builtin function.  It blocks till the
1542
 
      result is ready.
 
1543
      Equivalent of the :func:`apply` built-in function.  It blocks till the
 
1544
      result is ready.  Given this blocks, :meth:`apply_async` is better suited
 
1545
      for performing work in parallel. Additionally, the passed
 
1546
      in function is only executed in one of the workers of the pool.
1543
1547
 
1544
1548
   .. method:: apply_async(func[, args[, kwds[, callback]]])
1545
1549
 
1552
1556
 
1553
1557
   .. method:: map(func, iterable[, chunksize])
1554
1558
 
1555
 
      A parallel equivalent of the :func:`map` builtin function (it supports only
 
1559
      A parallel equivalent of the :func:`map` built-in function (it supports only
1556
1560
      one *iterable* argument though).  It blocks till the result is ready.
1557
1561
 
1558
1562
      This method chops the iterable into a number of chunks which it submits to
1561
1565
 
1562
1566
   .. method:: map_async(func, iterable[, chunksize[, callback]])
1563
1567
 
1564
 
      A variant of the :meth:`map` method which returns a result object.
 
1568
      A variant of the :meth:`.map` method which returns a result object.
1565
1569
 
1566
1570
      If *callback* is specified then it should be a callable which accepts a
1567
1571
      single argument.  When the result becomes ready *callback* is applied to
1577
1581
      make make the job complete **much** faster than using the default value of
1578
1582
      ``1``.
1579
1583
 
1580
 
      Also if *chunksize* is ``1`` then the :meth:`next` method of the iterator
 
1584
      Also if *chunksize* is ``1`` then the :meth:`!next` method of the iterator
1581
1585
      returned by the :meth:`imap` method has an optional *timeout* parameter:
1582
1586
      ``next(timeout)`` will raise :exc:`multiprocessing.TimeoutError` if the
1583
1587
      result cannot be returned within *timeout* seconds.
1698
1702
   generally be omitted since it can usually be inferred from the format of
1699
1703
   *address*. (See :ref:`multiprocessing-address-formats`)
1700
1704
 
1701
 
   If *authentication* is ``True`` or *authkey* is a string then digest
 
1705
   If *authenticate* is ``True`` or *authkey* is a string then digest
1702
1706
   authentication is used.  The key used for authentication will be either
1703
1707
   *authkey* or ``current_process().authkey)`` if *authkey* is ``None``.
1704
1708
   If authentication fails then :exc:`AuthenticationError` is raised.  See
1740
1744
 
1741
1745
   If *authkey* is ``None`` and *authenticate* is ``True`` then
1742
1746
   ``current_process().authkey`` is used as the authentication key.  If
1743
 
   *authkey* is ``None`` and *authentication* is ``False`` then no
 
1747
   *authkey* is ``None`` and *authenticate* is ``False`` then no
1744
1748
   authentication is done.  If authentication fails then
1745
1749
   :exc:`AuthenticationError` is raised.  See :ref:`multiprocessing-auth-keys`.
1746
1750
 
2216
2220
 
2217
2221
.. literalinclude:: ../includes/mp_benchmarks.py
2218
2222
 
2219
 
An example/demo of how to use the :class:`managers.SyncManager`, :class:`Process`
2220
 
and others to build a system which can distribute processes and work via a
2221
 
distributed queue to a "cluster" of machines on a network, accessible via SSH.
2222
 
You will need to have private key authentication for all hosts configured for
2223
 
this to work.
2224
 
 
2225
 
.. literalinclude:: ../includes/mp_distributing.py