I had an error with some multiprocessing with the pool (pop index out of range) and when I tried to simplify my code to post it here I get another error, so it's kind puzzling, see the code here:
def some_function(a, b):
return a*b
neigbhourhood = [[object() for _ in range(3)] for _ in range(3)]
result = [[object() for _ in range(3)] for _ in range(3)]
pool = Pool()
for i in range(0, 3):
for j in range(0, 3):
neigbhourhood[i][j] = pool.apply_async(some_function(i, j))
for k in range(0, 3):
for l in range(0, 3):
result[k][l] = neigbhourhood[k][l].get()
pool.close()
The traceback is about an int object not callable at the line 34 (the line with the get).
Edit: Ok it was just a typing error in the parameters of the pool.apply_async, now it's working but my real code is still randomly crashing and I can not repeat the error when I'm simplifying the code, I don't get it.
get", but instead your passing the function result topool.apply_async.some_function(i, j)already computes the result, what you want to do is pass the function as first parameter and the function arguments as tuple, i.e.pool.apply_async(some_function, (i, j)).