Python: "int not callable" with multiprocessing with pool

1.4k Views Asked by At

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.

1

There are 1 best solutions below

2
On BEST ANSWER

The problem lies in the way you are calling apply_async. It requires you to pass a function callback and arguments that will be passed to the provided function.

pool.apply.async(some_function, [x, y])