-
Notifications
You must be signed in to change notification settings - Fork 0
multiProcExample
holzkohlengrill edited this page Dec 15, 2023
·
2 revisions
#!/usr/bin/env python3
import sys
import multiprocessing
def dummyFctnOneInput(i):
i += 1
return i
def dummyFctnMultipleInputs(i, j):
res = i + j
return res
def main(args):
# single parameter in dummyFctnOneInput
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count()) # create threads
res = pool.map(dummyFctnOneInput, input_values) # input_values = a list of inputs
# multiple parameters in dummyFctnMultipleInputs
input_multi_values = zip(inputListOne, inputListTwo) # create list of tuples of input lists
res = pool.starmap(dummyFctnMultipleInputs, input_multi_values) # input_multi_values: e.g. [(i_1, j_1), (i_2, j_2), ... (i_n, j_n)]
if __name__ == "__main__":
main(sys.argv[1:])
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License *.
Code (snippets) are licensed under a MIT License *.
* Unless stated otherwise