Created
February 16, 2023 04:53
-
-
Save dustycodes/ccddd6fe029d6493dc9cb6bec9114eea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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