Created
October 7, 2020 12:33
-
-
Save AlbertSuarez/13cfe659a6c77890446ab7435efa613b to your computer and use it in GitHub Desktop.
run_multiple_functions_in_parallel.py
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 threading import Thread | |
def run_in_parallel(*args): | |
threads = list() | |
num_args = len(args) | |
results = [None] * num_args | |
for idx in range(num_args): | |
function_target, function_args = args[idx] | |
threads.append(Thread(target=function_target, args=(results, idx) + function_args)) | |
threads[idx].start() | |
for idx in range(num_args): | |
threads[idx].join() | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment