Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R stuck when calling a python function with multiprocessing module using reticulate #1353

Closed
doorholez opened this issue Mar 14, 2023 · 4 comments
Labels

Comments

@doorholez
Copy link

doorholez commented Mar 14, 2023

I am trying to call a python function with a multiprocessing module, but R always stucks when calling the function.
Here is a simple example to replicate the problem.
python script (test.py):

from multiprocessing import Pool
def f(a):
    print(a)
    return a ** 2
def f2():
    p = Pool(5)
    rtn = p.map(f, [1,2,3,4,5])
    return rtn
if __name__ == "__main__":
    print(f2())

R script (test.R):

test_py = reticulate::import("test1")
print("Processing python program...")
rlt = test_py$f2()
print("Python program finished.")

I can run the python script in python, but R always stucks in the line 'test_py$f2()'
Can you please guide me how to call python function with multiprocessing module in R?
Thanks.

@t-kalinowski
Copy link
Member

Hi, thank you for the helpful reprex. Unfortunately I can't reproduce the error, either in the terminal or the RStudio IDE. Can you please share more details about your environment (e.g., sessioninfo::sessioninfo())?

image
image

@doorholez
Copy link
Author

Oh, I tried it on the linux server and it works. But it still not working and stuck on my Windows PC. I noticed that when I run the script, the CPU usage of Windows Defender comes high. Maybe that's the problem? Here is my Windows PC environment:

- Session info -------------------------------------------------------------
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Chinese (Simplified)_China.936
 ctype    Chinese (Simplified)_China.936
 tz       Asia/Taipei
 date     2023-03-16
 rstudio  2021.09.1+372 Ghost Orchid (desktop)
 pandoc   NA

- Packages -----------------------------------------------------------------
 package     * version date (UTC) lib source
 cli           3.6.0   2023-01-09 [1] CRAN (R 4.2.2)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.2)

 [1] C:/Users/66437/AppData/Local/R/win-library/4.2
 [2] D:/R/R-4.2.2/library

----------------------------------------------------------------------------

And here is the screenshot of task manager. You can see the Window Defender is running automatically.
_JSQT GZOA OGZDGX``(VXF

@doorholez
Copy link
Author

Besides,it seems to appear on others Windows PC. I also reproduced it on the Windows 11 OS and I find another guy with the same problem. https://stackoverflow.com/questions/73777013/how-can-i-successfully-call-python-script-in-r-using-reticulate-when-having-m

@t-kalinowski
Copy link
Member

I believe this was fixed with #1461.
Please try the development version of reticulate

remotes::install_github("rstudio/reticulate")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants