Created
October 27, 2022 18:06
-
-
Save duskvirkus/0fa6dd15451883dc03a11683c814f2e7 to your computer and use it in GitHub Desktop.
Revisions
-
duskvirkus created this gist
Oct 27, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import concurrent.futures from tqdm import tqdm import random import time def run_on_thread_example(packed_args): arg_one, arg_two = packed_args time.sleep(int(random.random() * 2)) result = arg_one * arg_two print(f"arg_one: {arg_one}, arg_two: {arg_two:.2f}, result: {result:.2f}") return { "index": arg_one, "result": result, } if __name__ == "__main__": arg_list_one = [i for i in range(50)] arg_list_two = [random.random() for _ in range(len(arg_list_one))] with concurrent.futures.ThreadPoolExecutor() as executor: results = list(tqdm(executor.map(run_on_thread_example, zip(arg_list_one, arg_list_two)), total=len(arg_list_one))) print(results)