2

I would like to multiprocess a function (see below)

def func(c):
    time =  time
    list = [c, time]
    another_func(list)

I run this above function as follows:

p = multiprocess.Pool()
p.map(func, cust, chunksize=1)
p.close()
p.join()

cust is a list of strings like

cust = ['c1', 'c2', ...]

Now my question is it possible to get the time variable into the p.map like

p.map(func, cust, time, chunksize=1) 

I have searched multiple topics here but I did not find a matching topic.

Thx for any help/hints!

2
  • Pass a tuple of the values ;) Commented Mar 19, 2020 at 9:35
  • can you show the value of variable time ? Commented Mar 19, 2020 at 9:59

1 Answer 1

3

you can use starmap:

def func(c, time):
    my_list = [c, time]
    another_func(my_list)


p.starmap(func, [(c, time) for c in cust], chunksize=1) 

even better:

p.map(another_func, [[c, time] for c in cust], chunksize=1) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.