Search⌘ K
AI Features

Miscellaneous Functions

Explore how to use Python's concurrent.futures wait and as_completed methods to handle multiple futures. Understand different waiting strategies and timeout effects for better concurrency management.

We'll cover the following...

Miscellaneous Functions

The concurrent.futures module provides two methods to wait for futures collectively. These are:

  • wait

  • as_completed

Let's discuss each with examples below.

wait ( )

The wait() method takes in an iterable consisting of futures. These futures could be futures returned from thread or process pools. Next, it takes a timeout value, which if elapsed will return from the wait() call irrespective of how many futures have completed. ...