1

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.

2
  • Please provide the full traceback. Commented Jan 4, 2017 at 10:54
  • It seems that the problem is not arising from "the line with the get", but instead your passing the function result to pool.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)). Commented Jan 4, 2017 at 11:01

1 Answer 1

3

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])
Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't it return an ApplyResult Object (that I transform in int with the get() ) ? What should I do?
@RaphaelTodo some_function produces a result before apply_async gets called. So you will actually supply an int as callback function which obviously doesn't work

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.