I have a function that takes multiple arguments, some of which are boolean. I’m trying to pass this to the multiprocessing pool.apply_async and want to pass some args with the names attached.
Here’s an example script that I’m working with:
from multiprocessing import Pool
def testFunc(y, x, calcY=True):
if calcY == True:
return y*y
elif calcY == False:
return x*x
if __name__ == "__main__":
p = Pool()
res = p.apply_async(testFunc, args = (2, 4, False))
print res.get()
This works, but I’m curious about changing the res = p.apply_async(testFunc, args = (2, 4, False)) to something like:
res = p.apply_async(testFunc, args = (2, 4, calcY = False))
apply_async has
argsandkwdskeyword arguments which you could use like this: