'Python2: multiprocessing.dummy.Pool vs multiprocessing.pool.ThreadPool

In python 2, is there any difference between multiprocessing.dummy.Pool and multiprocessing.pool.ThreadPool? The source code seems to imply they're the same.



Solution 1:[1]

They're the same (both on Py2 and Py3); multiprocessing.dummy.Pool is just a thin wrapper that imports and calls multiprocessing.pool.ThreadPool. The actual code is just:

def Pool(processes=None, initializer=None, initargs=()):
    from multiprocessing.pool import ThreadPool
    return ThreadPool(processes, initializer, initargs)

In general, I'd prefer using multiprocessing.dummy.Pool only because the existence of multiprocessing.dummy is officially documented, where multiprocessing.pool is not (it's an internal implementation detail).

Update: As of Python 3.7, the multiprocessing.dummy docs explicitly document the existence of multiprocessing.pool.ThreadPool, so if you're definitely using threads and will never want to switch, arguably ThreadPool is better for being explicit about threads being used. If you might be switching back and forth, it's easier if all you have to do is add and remove .dummy from:

from multiprocessing import Pool  # And maybe other imports that need to switch for process vs. threads

so I'd recommend continuing to use Pool in that case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1