Skip to content

Instantly share code, notes, and snippets.

@dustycodes
Created February 16, 2023 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustycodes/ccddd6fe029d6493dc9cb6bec9114eea to your computer and use it in GitHub Desktop.
Save dustycodes/ccddd6fe029d6493dc9cb6bec9114eea to your computer and use it in GitHub Desktop.
from concurrent.futures import ThreadPoolExecutor, as_completed
from tqdm import tqdm
def get_data(
static_param1: int, static_param2: int, dynamic_param: int
):
return static_param1 * static_param2 * dynamic_param
results = []
static_param_1 = 1
static_param_2 = 2
dynamic_params = [1, 2, 3, 4]
with ThreadPoolExecutor() as executor:
futures = {
executor.submit(
get_data,
static_param_1,
static_param_2,
x
): x for x in dynamic_params
}
for future in tqdm(
as_completed(futures),
total=len(dynamic_params),
desc="Retrieving data",
):
results.append(future.result())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment