I would like to know in what scenarios python's multiprocessing
libary would give the Can't pickle <type 'instancemethod'>
error when using the pool.apply_async
, but not when using the process.start
method. If I understood correctly, the process.start
method should also be pickling the code, so not much should differ in terms of requirements, or am I mistaken?
Here is the general structure of the code I am having this issue with (the actual functions are too long and complex to condense accurately):
import multiprocessing as mult
def f2(name):
print 'hello' + name
def f1(x):
return str(x)
if __name__ == '__main__':
#This works fine
processes = []
for x in xrange(100):
name = f1(x)
p = mult.Process(target=f2, args=(name,))
processes.append(p)
for p in processes:
p.start()
if __name__ == '__main__':
#This gives the pickle error
pool = mult.Pool()
for x in xrange(100,200):
name = f1(x)
pool.apply_async(f2, args=(name,))
pool.close()
Note: the completed processes do not need to join with the main process after completing. Also, I am running this on Win7 64 with a 64bit version of Python.
I hope this question is different enough from this one.