I am setting up a Programm which exports PDF Files and now I want to speed it up by using Pythons multiprocessing module and the map function (I am using Python 3.7.9).
Now I am running into trouble applying the multiprocessing to my code. I tried to break down the code into its essentials which then looks like this:
from multiprocessing import Pool
def callFunctionInClass(i):
#calls the function inside the class which is supposed to be parallelized
SomeClass().func1(i)
class SomeClass:
def setupUi(self):
# sets up the Graphical user interface
return
def func1(self, i):
currentListItem = self.someList[i]
#from here on out I create a PDF which then is exported
def parallelizationFunction(self):
#set up the pool
pool = Pool()
# range which the map function is supposed to iterate over
someRange = list(range(0, len(self.someList)))
pool.map(callFunctionInClass, someList)
if __name__ == "__main__":
#calls the class and sets up the GUI
ui = SomeClass()
ui.setupUi()
Inside the class the pool is initialized and the top level method is called using map, which then is supposed to call the class-method that I want to use multiproccessing on. Now similar questions have already been asked here and I tried to adopt according to the answers but I still run into errors (mostly pickling errors).
So far I tried several things, like passing self to the top-level-methodor using pathos ProcessingPool but I could also not get this to work. My question is how can I pass class values to methods outside its scope without running into pickling errors (maybe multiprocessing.Value does the job)?
I hope my question is not too vague, otherwise I'll try to provide more sufficient information.
Many thanks in advance!