Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiprocessing, pool and two lists

Tags:

python

>>> from multiprocessing import Pool

>>> def f(x, y):
...     return x*y

>>> p = Pool(3)

>>> p.map(f, [1,2,3], [4,5,6])

And I look errors TypeError: unorderable types: list() <= int().
How to use Pool with 2 lists?

like image 644
Serhii Avatar asked Nov 16 '25 08:11

Serhii


1 Answers

The problem is with the map function not the Pool object. For this case, starmap would be a good choice like this:

p.starmap(f, zip([1,2,3], [4,5,6]))

From python 3.3 starmap was added to the Pool object

like image 75
damores Avatar answered Nov 17 '25 21:11

damores