Apply updates sent to PEPs list by Brian Quinlan.

This commit is contained in:
Georg Brandl 2010-05-01 09:40:47 +00:00
parent 7da36514e9
commit ebeb712eea
1 changed files with 40 additions and 17 deletions

View File

@ -149,6 +149,9 @@ processes to execute calls asynchronously. The callable objects and arguments
passed to `ProcessPoolExecutor.submit` must be serializeable according to the passed to `ProcessPoolExecutor.submit` must be serializeable according to the
same limitations as the multiprocessing module. same limitations as the multiprocessing module.
Calling `Executor` or `Future` methods from within a callable submitted to a
`ProcessPoolExecutor` will result in deadlock.
`__init__(max_workers)` `__init__(max_workers)`
Executes calls asynchronously using a pool of a most *max_workers* Executes calls asynchronously using a pool of a most *max_workers*
@ -215,11 +218,11 @@ will be cancelled and the method will return `True`.
Return `True` if the call was successfully cancelled. Return `True` if the call was successfully cancelled.
`Future.running()` `running()`
Return `True` if the call is currently being executed and cannot be cancelled. Return `True` if the call is currently being executed and cannot be cancelled.
`Future.done()` `done()`
Return `True` if the call was successfully cancelled or finished running. Return `True` if the call was successfully cancelled or finished running.
@ -248,6 +251,25 @@ be raised.
If the call completed without raising then ``None`` is returned. If the call completed without raising then ``None`` is returned.
`add_done_callback(fn)`
Attaches a function *fn* to the future that will be called when the future is
cancelled or finishes running. *fn* will be called with the future as its only
argument.
If the future has already completed or been cancelled then *fn* will be called
immediately. If the same function is added several times then it will still only
be called once.
NOTE: This method can be used to create adapters from Futures to Twisted
Deferreds.
`remove_done_callback(fn)`
Removes the function *fn*, which was previously attached to the future using
`add_done_callback`. `KeyError` is raised if the function was not previously
attached.
Internal Future Methods Internal Future Methods
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
@ -284,14 +306,10 @@ Module Functions
`wait(fs, timeout=None, return_when=ALL_COMPLETED)` `wait(fs, timeout=None, return_when=ALL_COMPLETED)`
Wait for the `Future` instances in the given sequence to complete. Returns a Wait for the `Future` instances given by *fs* to complete. Returns a named
named 2-tuple of sets. The first set, named "finished", contains the futures 2-tuple of sets. The first set, named "finished", contains the futures that
that completed (finished or were cancelled) before the wait completed. The completed (finished or were cancelled) before the wait completed. The second
second set, named "not_finished", contains uncompleted futures. set, named "not_finished", contains uncompleted futures.
This method should always be called using keyword arguments, which are:
*fs* is the sequence of Future instances that should be waited on.
*timeout* can be used to control the maximum number of seconds to wait before *timeout* can be used to control the maximum number of seconds to wait before
returning. If timeout is not specified or None then there is no limit to the returning. If timeout is not specified or None then there is no limit to the
@ -313,11 +331,11 @@ following constants:
`as_completed(fs, timeout=None)` `as_completed(fs, timeout=None)`
Returns an iterator over the Future instances given by *fs* that yields futures Returns an iterator over the `Future` instances given by *fs* that yields
as they complete (finished or were cancelled). Any futures that completed futures as they complete (finished or were cancelled). Any futures that
before `as_completed()` was called will be yielded first. The returned iterator completed before `as_completed()` was called will be yielded first. The returned
raises a `TimeoutError` if `__next__()` is called and the result isn't available iterator raises a `TimeoutError` if `__next__()` is called and the result isn't
after *timeout* seconds from the original call to `as_completed()`. If available after *timeout* seconds from the original call to `as_completed()`. If
*timeout* is not specified or `None` then there is no limit to the wait time. *timeout* is not specified or `None` then there is no limit to the wait time.
========= =========
@ -351,13 +369,14 @@ method calls as asynchronous. A proxy result would be returned while the
operation is eagerly evaluated asynchronously, and execution would only operation is eagerly evaluated asynchronously, and execution would only
block if the proxy object were used before the operation completed. block if the proxy object were used before the operation completed.
Anh Hai Trinh proposed a simpler but more limited API concept [5]_. Anh Hai Trinh proposed a simpler but more limited API concept [5]_ and the API
has been discussed in some detail on stdlib-sig [6]_.
======================== ========================
Reference Implementation Reference Implementation
======================== ========================
The reference implementation [6]_ contains a complete implementation of the The reference implementation [7]_ contains a complete implementation of the
proposed design. It has been tested on Linux and Mac OS X. proposed design. It has been tested on Linux and Mac OS X.
========== ==========
@ -385,6 +404,10 @@ References
`http://www.mail-archive.com/stdlib-sig@python.org/msg00480.html` `http://www.mail-archive.com/stdlib-sig@python.org/msg00480.html`
.. [6] .. [6]
A discussion of the proposed API on stdlib-sig
`http://mail.python.org/pipermail/stdlib-sig/2009-November/000731.html`
.. [7]
Reference `futures` implementation Reference `futures` implementation
`http://code.google.com/p/pythonfutures/source/browse/#svn/branches/feedback` `http://code.google.com/p/pythonfutures/source/browse/#svn/branches/feedback`