0

I've recently switched from my MacBook to my windows PC and my multithreading is no longer running. 8 python processes spin up in task manager but they all use 0% CPU and the ParalellMonteCarlo does not return anything (it just runs eternally). This code worked fine on my MacBook and google colab so I assume it is a problem with windows.

def Sample():
    return 'test'

def _paralell_mc(num_iter):
    pool=mp.Pool(8)
    future_res = [pool.apply_async(Sample, for _ in range(num_iter)]    
    res = [f.get() for f in future_res]
    return res

def ParalellMonteCarlo(num_iter=100):
    samples = _paralell_mc(num_iter)
    return samples

(code simplified to demonstrate the problem - this does not terminate)

Thanks in advance!

AMC
  • 2,642
  • 7
  • 13
  • 35
STKN
  • 1
  • Is that a typo in `[pool.apply_async(Sample, for _ in range(num_iter)]` ? – AMC Mar 23 '20 at 21:38
  • Upon further research, it appears that it is an issue with jupyter lab/windows - we have to put the sample function into a separate .py file and run the parallel_mc within an if name = main clause in jupyter. – STKN Mar 24 '20 at 09:12
  • Ah, I hadn't realized that you're on Windows. Take a look at https://stackoverflow.com/questions/20222534/python-multiprocessing-on-windows-if-name-main. As an aside, variable and function names should follow the `lower_case_with_underscores` style. – AMC Mar 25 '20 at 18:19

0 Answers0