Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b1055197
Commit
b1055197
authored
Dec 08, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add example for concurrent.futures.
parent
3fcf0029
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+25
-5
No files found.
Doc/whatsnew/3.2.rst
View file @
b1055197
...
...
@@ -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::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment