Skip to content

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:])

Python 3

(un)fold
Snippets
General
Libs

Linux/bash

(un)fold
Guides
Scripts

Git

(un)fold

C/C++

(un)fold

Video

(un)fold

Databases

(un)fold

Misc

(un)fold

Windows

(un)fold

Mac

(un)fold

SW recommendations

(un)fold

(Angular) Dart

(un)fold

Clone this wiki locally