I'm currently trying to use pool multiprocessing function in order to calculate multiple part of tables at the same time. My code is basically:

def funtion(tab1,tab2,...)
  ...

def function_wrapper(args):
  return function(*args)

pool = Pool(processes=num_thread)
arg = [(table1(i,:),table2(i,:),...)for i in range(1000)]
pool.map(function_wrapper, arg)
pool.close()
pool.join() 

And I get the error: IndexError: too many indices .

Is someone can help me to write correctly this? Thanks.

有帮助吗?

解决方案

table1(i,:) should have raised a SyntaxError. funtion should probably be function. Please modify the code below so that we have runnable code which exhibits the IndexError. Otherwise, as you can see below, there is no error in the code you posted.

import multiprocessing as mp
def function(tab1,tab2):
    return tab1+tab2

def function_wrapper(args):
    return function(*args)

if __name__ == '__main__':
    pool = mp.Pool()
    arg = [(i,i) for i in range(1000)]
    print(pool.map(function_wrapper, arg))
    pool.close()
    pool.join() 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top