Skip to content

Commit

Permalink
fix running under radian
Browse files Browse the repository at this point in the history
closes #1668
  • Loading branch information
t-kalinowski committed Sep 16, 2024
1 parent 6592fa7 commit 817c988
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,12 +2844,10 @@ SEXP main_process_python_info_unix() {
return R_NilValue;
}


if (PyGILState_Ensure == NULL)
loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure);

if (PyGILState_Release == NULL)
if (PyGILState_Release == NULL) {
loadSymbol(pLib, "PyGILState_Release", (void**)&PyGILState_Release);
loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure);
}

GILScope scope;

Expand Down Expand Up @@ -2930,6 +2928,19 @@ void py_initialize(const std::string& python,
if (Py_IsInitialized()) {
// if R is embedded in a python environment, rpycall has to be loaded as a regular
// module.

// We don't currently support running embedded on windows?

This comment has been minimized.

Copy link
@randy3k

randy3k Sep 16, 2024

Contributor

As far as I can tell, the previous version v1.38 is compatible running embedded on windows.
See for example this test for rchitect (a package used by radian to initialize R) https://github.com/randy3k/rchitect/actions/runs/10399127851/job/28797737515

This comment has been minimized.

Copy link
@t-kalinowski

t-kalinowski Sep 16, 2024

Author Member

Thanks. I'll likely have to start up a Windows EC2 instance to track this down.

From reading the code, it looks like we check for embeddedness with !is.null(main_process_python_info()

py_embedded <- !is.null(main_process_python_info())

and main_process_python_info() always returns NULL on Windows,

reticulate/src/python.cpp

Lines 2807 to 2810 in 6592fa7

SEXP main_process_python_info_win32() {
// NYI
return R_NilValue;
}

This comment has been minimized.

Copy link
@randy3k

randy3k Sep 16, 2024

Contributor

If I remember correctly, on windows, symbols are not loaded into the main process, they will to be loaded from the DLL directly via LoadLibraryEx.

#ifndef _WIN32
void* pLib = NULL;
pLib = ::dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
// replace symbols that we initialized with dummy functions
// in reticulate_init
loadSymbol(pLib, "PyIter_Check", (void**) &PyIter_Check);
loadSymbol(pLib, "PyCallable_Check", (void**) &PyCallable_Check);
loadSymbol(pLib, "PyGILState_Ensure", (void**) &PyGILState_Ensure);
::dlclose(pLib);
#endif

GILScope scope;
PyImport_AddModule("rpycall");
PyDict_SetItemString(PyImport_GetModuleDict(), "rpycall", initializeRPYCall());
Expand Down

0 comments on commit 817c988

Please sign in to comment.