I am trying to use the multiprocessing
package to call a function (let's call it myfunc
) in parallel, specifically using pool.map
i.e. pool.map(myfunc, myarglist)
. When I simply loop over myarglist
without using multiprocessing
there are no errors, which should be the case because all operations in myfunc
are called within a try
block. However, when I call the function using pool.map
the script invariably stops running, i.e. it stop printing a "myfunc done!" statement within my function and the processes stop using the CPUs, but it never returns resultlist
. I am running python 2.7 from the terminal in ubuntu 12.04. What could cause this to occur and how should I fix/troubleshoot the problem?
cpu_count = int(multiprocessing.cpu_count())
pool = Pool(processes = cpu_count)
resultlist = pool.map(myfunc, myarglist)
pool.close()
Update
One issue when using multiprocessing can be the size of the object, if you think that may be a problem see this answer. As the answer notes "If this [solution] doesn't work, maybe the stuff you're returning from your functions is not pickleable, and therefore unable to make it through the Queues properly." Multiprocessing passes objects between processes by pickling them. It turns out that one or two of my objects had soup from BeautifulSoup
that would not pickle.
myfunc
. – Boykinmyfunc
and the pool.map() call completes. So it seems to be having troubles at the stage where pool.map combines the results. In looking at the system monitor though nothing is happening in any of the python processes at this point. And it is taking longer than it would to simply run on a single core. – Polyphagiaresult.get()
hangs. Interestingly(?), if and only if I callmyfunc
on that object not in parallel right before I call myfunc on the object usingmap_async
I get the error message "Segmentation fault (core dumped)" before I even callresult.get()
. – Polyphagiatry
statement and function itself does not seem to be the problem, but returning the function's result in parallel is. – Polyphagiamyfunc
or trying to return frommyfunc
. If that is indeed happening,map
would hang forever. – Southermyfunc
, or the object being passed tomyfunc
? – Souther