I'm trying to use multiprocessing in python (2.7.8) on a Mac OSX. After reading Velimir Mlaker's answer to this question, I was able to use multiprocessing.Pool() to multiprocess a trivially simple function but it doesn't work with my actual function. I get the right results but it executes serially. I believe the problem is that my function loops over a music21.stream() which is similar to a list but has special functionality for music data. I believe that music21 streams cannot be pickled so is there some multiprocessing alternative to pool that I can use? I don't mind if results are returned out of order and I can upgrade to a different version of python if necessary. I've included my code for the multiprocessing task but not for the stream_indexer() function it calls. Thank you!
import multiprocessing as mp
def basik(test_piece, part_numbers):
jobs = []
for i in part_numbers:
# Each 2-tuple in jobs has an index <i> and a music21 stream that
# corresponds to an individual part in a musical score.
jobs.append((i, test_piece.parts[i]))
pool = mp.Pool(processes=4)
results = pool.map(stream_indexer, jobs)
pool.close()
pool.join()
return results