summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-08 06:42:41 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-08 06:42:41 (GMT)
commitb105519710152a43f9d88f9df466ad197ae35a99 (patch)
tree4c0622b0de43bd7f7ce39b02d6957f5c26882186 /Doc
parent3fcf0029945d8c6f866fdbb98517136999d7be7e (diff)
downloadcpython-b105519710152a43f9d88f9df466ad197ae35a99.zip
cpython-b105519710152a43f9d88f9df466ad197ae35a99.tar.gz
cpython-b105519710152a43f9d88f9df466ad197ae35a99.tar.bz2
Add example for concurrent.futures.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/whatsnew/3.2.rst30
1 files changed, 25 insertions, 5 deletions
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index e17292c..f386d7c 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -223,11 +223,31 @@ components so that process and thread limits can be centrally managed. This
solves the design challenge that arises when each component has its own
competing strategy for resource management.
-For an example of :class:`~concurrent.futures.ThreadPoolExecutor`,
-see :ref:`code for threaded parallel URL reads<threadpoolexecutor-example>`.
-
-For an example of :class:`~concurrent.futures.ProcessPoolExecutor`,
-see :ref:`code for computing prime numbers in parallel<processpoolexecutor-example>`.
+Both classes share a common interface with three methods:
+:meth:`~concurrent.futures.Executor.submit` for scheduling a callable and
+returning a :class:`~concurrent.futures.Future` object;
+:meth:`~concurrent.futures.Executor.map` for scheduling many asynchronous calls
+at time, and :meth:`~concurrent.futures.shutdown` for freeing resources. The
+class is a :term:`context manager` and can be used within a :keyword:`with`
+statement to assure that resources are automatically released when currently
+pending futures are done executing.
+
+A simple of example of :class:`~concurrent.futures.ThreadPoolExecutor` is a
+launch of four parallel threads for copying directories::
+
+ import shutil
+ with ThreadPoolExecutor(max_workers=4) as e:
+ e.submit(shutil.copy, 'src1.txt', 'dest1.txt')
+ e.submit(shutil.copy, 'src2.txt', 'dest2.txt')
+ e.submit(shutil.copy, 'src3.txt', 'dest3.txt')
+ e.submit(shutil.copy, 'src3.txt', 'dest4.txt')
+
+Also see :ref:`code for threaded parallel URL reads<threadpoolexecutor-example>`
+for an example using threads to fetch multiple web pages in parallel.
+
+Or, for an example of :class:`~concurrent.futures.ProcessPoolExecutor`, see
+:ref:`code for computing prime numbers in
+parallel<processpoolexecutor-example>`.
.. seealso::