How can I successfully call python script in R using [reticulate] when having 'multiprocessing' module in python script?

Viewed 25

I am trying to use reticulate package to call python script in R. Previously, it run successfully but this time, the python script includes the multiprocessing module, then I cannot run through. And in RStudio, it always stuck there.

Here is the tested python script, named test_multiprocessing.py.

# test_multiprocessing.py
from multiprocessing import Pool
def f(x):
    return x*x

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(f, [1, 2, 3]))

I can run the above script in python, but in RStudio as below:

library(reticulate)
condaEnvName = 'myEnv'
reticulate::use_condaenv(condaEnvName, required = TRUE)
reticulate::source_python('./test_multiprocessing.py')

The R always stuck there.

Can you please guide me how can we successfully call the python script in R when using multiprocessing module in the python script like above one?

I am using Windows 10 OS.

Thanks.

0 Answers
Related