Multiprocessing is a multi-process library for Python, and Multiprocessing.dummy is a multi-threaded version that uses the same.
There is a pool concept, and the process pool/thread pool has a common approach, in which the methods are compared as follows:
There is four choices to mapping jobs to process. Here is the differences:
Multi-args Concurrence Blocking Ordered-resultsmap no yes yes yesapply yes no yes nomap_async no yes no yesapply_async yes yes no no
In Python 3, a new function starmap can accept multiple arguments.
Note that map map_asyncand is called for a list of jobs in one time, but and can only called for one apply apply_async job. However, apply_async execute a job in background therefore in parallel. See examples:
#MapResults = Pool.map (worker, [1, 2, 3])#Apply forX, yinch[[1, 1], [2, 2]]: results.append (pool.apply (Worker, (x, y)))defCollect_result (Result): Results.append (Result)#Map_asyncPool.map_async (worker, Jobs, callback=Collect_result)#Apply_async forX, yinch[[1, 1], [2, 2]]: Pool.apply_async (worker, (x, y), callback=collect_result)
原文地址: http://blog.shenwei.me/python-multiprocessing-pool-difference-between-map-apply-map_async-apply_async/
Python multiprocessing. The difference between map, Map_async, apply, Apply_async in Pool