Minor clarifications.

This commit is contained in:
Guido van Rossum 2013-05-29 15:33:55 -07:00
parent dfb7f691ac
commit cdc8dab2ce
1 changed files with 18 additions and 12 deletions

View File

@ -846,6 +846,12 @@ public API is as follows, indicating the differences with PEP 3148:
convention from the section "Callback Style" below) is always called convention from the section "Callback Style" below) is always called
with a single argument, the Future object. with a single argument, the Future object.
- ``remove_done_callback(fn)``. Remove the argument from the list of
callbacks. This method is not defined by PEP 3148. The argument
must be equal (using ``==``) to the argument passed to
``add_done_callback()``. Returns the number of times the callback
was removed.
- ``set_result(result)``. The Future must not be done (nor cancelled) - ``set_result(result)``. The Future must not be done (nor cancelled)
already. This makes the Future done and schedules the callbacks. already. This makes the Future done and schedules the callbacks.
Difference with PEP 3148: This is a public API. Difference with PEP 3148: This is a public API.
@ -1302,25 +1308,25 @@ package are provided:
- ``FIRST_EXCEPTION``: Wait until at least one Future is done (not - ``FIRST_EXCEPTION``: Wait until at least one Future is done (not
cancelled) with an exception set. (The exclusion of cancelled cancelled) with an exception set. (The exclusion of cancelled
Futures from the filter is surprising, but PEP 3148 does it this Futures from the condition is surprising, but PEP 3148 does it
way.) this way.)
- ``tulip.as_completed(fs, timeout=None)``. Returns an iterator whose - ``tulip.as_completed(fs, timeout=None)``. Returns an iterator whose
values are Futures; waiting for successive values waits until the values are Futures or coroutines; waiting for successive values
next Future or coroutine from the set ``fs`` completes, and returns waits until the next Future or coroutine from the set ``fs``
its result (or raises its exception). The optional argument completes, and returns its result (or raises its exception). The
``timeout`` has the same meaning and default as it does for optional argument ``timeout`` has the same meaning and default as it
``concurrent.futures.wait()``: when the timeout occurs, the next does for ``concurrent.futures.wait()``: when the timeout occurs, the
Future returned by the iterator will raise ``TimeoutError`` when next Future returned by the iterator will raise ``TimeoutError``
waited for. Example of use:: when waited for. Example of use::
for f in as_completed(fs): for f in as_completed(fs):
result = yield from f # May raise an exception. result = yield from f # May raise an exception.
# Use result. # Use result.
Note: if you do not wait for the futures as they are produced by the Note: if you do not wait for the values produced by the iterator,
iterator, your ``for`` loop may not make progress (since you are not your ``for`` loop may not make progress (since you are not allowing
allowing other tasks to run). other tasks to run).
Sleeping Sleeping
-------- --------