I'm following the answer on Is there a simple process-based parallel map for python? using Python 3.6.1
. I'm trying to use it the same exact way as I would use the regular map
function. Why does this happen? How can I create a parallel map
function for use with lambda
?
def map_parallel(func, iterable, n_jobs=-1):
if n_jobs == -1:
n_jobs = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=n_jobs)
return pool.map(func, iterable)
map_parallel(lambda x: x + 3, range(100))
PicklingError: Can't pickle <function <lambda> at 0x185284f28>: attribute lookup <lambda> on __main__ failed