Future objects
Future objects are instantiated whenever we submit a task to an executor, such as how we submitted tasks to ThreadPoolExecutor
in previous examples within this chapter. Future objects are objects that will, eventually, be given a value sometime in the future.
Methods in future objects
The future objects have the following methods with which we can access and modify them. Each of these methods will be covered in a full code sample further on in the chapter.
The result() method
The result()
method gives us any returned values from the future object. This result
method can be called like this:
futureObj.result(timeout=None)
By specifying the timeout
parameter, we, basically, put a time limit on our future object. If the future object fails to complete in the given time frame, then a concurrent.futures
. The timeout
error is raised. This is quite useful, as it gives us more control in terms of capping the amount of time erroneous threads can execute for, and limiting the damage they...