Skip to content

Instantly share code, notes, and snippets.

@AlbertSuarez
Created October 7, 2020 12:33
Show Gist options
  • Save AlbertSuarez/13cfe659a6c77890446ab7435efa613b to your computer and use it in GitHub Desktop.
Save AlbertSuarez/13cfe659a6c77890446ab7435efa613b to your computer and use it in GitHub Desktop.
run_multiple_functions_in_parallel.py
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