3
>>> 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?

Serhii
  • 1,367
  • 3
  • 13
  • 31

2 Answers2

5

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

damores
  • 2,251
  • 2
  • 18
  • 31
  • 1
    The mistake was on my side. Nice one! +1 – Ma0 Feb 28 '18 at 10:18
  • Actually, your comment made me research a bit further and see that I was unnecessarily importing `starmap` and notice it was added in 3.3, we'll have to see what version OP is using – damores Feb 28 '18 at 10:21
1

I don't really understand how you want to order your parameters but the idea is to have a list of tuples because your function takes 2 arguments, so something like this :

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

and make f take a tuple as argument

def f(t):
    return t[0] * t[1]
Gabriel Samain
  • 497
  • 3
  • 10