I've researched this question multiple times, but haven't found a workaround that either works in my case, or one that I understand, so please bear with me.
Basically, I have a hierarchical organization of functions, and that is preventing me from multiprocessing in the top-level. Unfortunately, I don't believe I can change the layout of the program - because I need all the variables that I create after the initial inputs.
For example, say I have this:
import multiprocessing
def calculate(x):
# here is where I would take this input x (and maybe a couple more inputs)
# and build a larger library of variables that I use further down the line
def domath(y):
return x * y
pool = multiprocessing.Pool(3)
final= pool.map(domath, range(3))
calculate(2)
This yields the following error:
Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
I was thinking of globals, but I'm afraid that I'd have to define too many and that may slow my program down quite a bit. Is there any workaround without having to restructure the whole program?