From the course: Python Parallel and Concurrent Programming Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Future: Python demo

Future: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 2

Start my 1-month free trial

Future: Python demo

- When you submit a task to an executor in Python, the submit method returns an instance of the future class, which encapsulates the asynchronous execution of the callable task. The future class has several methods that can be used to check the status of the task's execution. Cancel it if needed. And most importantly, it has a method named result which is used to retrieve the return value after the call has completed. To demonstrate that in action, I'll recreate my interaction with Olivia from the previous video, starting with this basic shell of a program. First, I'll import the thread pool executor class from the concurrent.futures module, and I'll also import the time module. Then I'll create a new function named how many vegetables, and this will serve as our callable task. Within that function, I'll print a message that Olivia is counting vegetables. Then I'll have the function sleep for three seconds. And finally, the function will return a value for the number of vegetables in…

Contents