It is pretty simple.
from multiprocessing import Pool def process_file(filename): return filename if __name__ == '__main__': pool = Pool() files = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] results = pool.imap(process_file, files) for result in results: print result
Pool automatically defaults to the number of processor cores that you have. Also, make sure your processing function is imported from a file and that your multiprocessing code is inside if __name__ == '__main__': If not, you will make a plug and lock your computer.
source share