0

I want to run a simple function across seperate cores on my computer. My computer has four cores.

To start with, a simple function:

def exp(x):

    return x**2

now I want to give this function four separate numbers, and use a different core to apply the function so that the calculations are done in parallel.

I am trying like this:

import multiprocessing as mp

if __name__ == "__main__":
    check = [1, 5, 6, 8]
    pool = mp.Pool( mp.cpu_count())
    results = pool.map(exp, check)

but this seems to execute and then it gets hung up, so I am not sure I am using pool correctly here.

I also tried this:

results = [pool.apply_async(cube, args=(x,)) for x in range(1,7)]
output = [p.get() for p in results]

but it gets hung on the last line again.

I am using ipython in ancondas spyder environment, this could also be why? Maybe I need to use ipythons parallel?

EDIT:

The answer to my problem was found here, multiprocessing in IPython console on Windows machine - if __name_ requirement

2
  • 1
    Can't repro. Works for me. What OS are you on? Commented Jul 18, 2017 at 19:14
  • hmmm, I'm on Windows 7 Commented Jul 18, 2017 at 19:15

0

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.