class concurrent.futures.Future
Encapsulates the asynchronous execution of a callable. Future instances are created by Executor.submit() and should not be created directly except for testing.
-
cancel() -
Attempt to cancel the call. If the call is currently being executed and cannot be cancelled then the method will return
False, otherwise the call will be cancelled and the method will returnTrue.
-
cancelled() -
Return
Trueif the call was successfully cancelled.
-
running() -
Return
Trueif the call is currently being executed and cannot be cancelled.
-
done() -
Return
Trueif the call was successfully cancelled or finished running.
-
result(timeout=None) -
Return the value returned by the call. If the call hasn’t yet completed then this method will wait up to timeout seconds. If the call hasn’t completed in timeout seconds, then a
concurrent.futures.TimeoutErrorwill be raised. timeout can be an int or float. If timeout is not specified orNone, there is no limit to the wait time.If the future is cancelled before completing then
CancelledErrorwill be raised.If the call raised, this method will raise the same exception.
-
exception(timeout=None) -
Return the exception raised by the call. If the call hasn’t yet completed then this method will wait up to timeout seconds. If the call hasn’t completed in timeout seconds, then a
concurrent.futures.TimeoutErrorwill be raised. timeout can be an int or float. If timeout is not specified orNone, there is no limit to the wait time.If the future is cancelled before completing then
CancelledErrorwill be raised.If the call completed without raising,
Noneis returned.
-
add_done_callback(fn) -
Attaches the callable fn to the future. fn will be called, with the future as its only argument, when the future is cancelled or finishes running.
Added callables are called in the order that they were added and are always called in a thread belonging to the process that added them. If the callable raises an
Exceptionsubclass, it will be logged and ignored. If the callable raises aBaseExceptionsubclass, the behavior is undefined.If the future has already completed or been cancelled, fn will be called immediately.
The following Future methods are meant for use in unit tests and Executor implementations.
-
set_running_or_notify_cancel() -
This method should only be called by
Executorimplementations before executing the work associated with theFutureand by unit tests.If the method returns
Falsethen theFuturewas cancelled, i.e.Future.cancel()was called and returned True. Any threads waiting on theFuturecompleting (i.e. throughas_completed()orwait()) will be woken up.If the method returns
Truethen theFuturewas not cancelled and has been put in the running state, i.e. calls toFuture.running()will return True.This method can only be called once and cannot be called after
Future.set_result()orFuture.set_exception()have been called.
-
set_result(result) -
Sets the result of the work associated with the
Futureto result.This method should only be used by
Executorimplementations and unit tests.
-
set_exception(exception) -
Sets the result of the work associated with the
Futureto theExceptionexception.This method should only be used by
Executorimplementations and unit tests.
Please login to continue.