Skip to content

Commit 911cb32

Browse files
committed
[Python] Avoid side effects in libROOTPythonizations initialization
There are some side effects when importing the ROOT CPython extension that we should better avoid, so that all active initialization is centralized in `ROOTFacade._finalSetup()`. Like this, it will be easier for us and our users to keep track of what the differences between the base cppyy and the ROOT C++ runtime are. That should help explaining to our users that they usually don't need to import cppyy directly,
1 parent 1f07751 commit 911cb32

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

bindings/pyroot/pythonizations/python/ROOT/_facade.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ def _finalSetup(self):
162162
from ._application import PyROOTApplication
163163
from ._pythonization import _register_pythonizations, pythonization
164164

165+
# signal policy: don't abort interpreter in interactive mode
166+
cppyy._backend.SetGlobalSignalPolicy(not cppyy.gbl.ROOT.GetROOT().IsBatch())
167+
165168
self.__dict__["_cppyy"] = cppyy
166169

167170
# Expose some functionality from CPyCppyy extension module

bindings/pyroot/pythonizations/src/PyROOTModule.cxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ struct module_state {
172172
PyObject *error;
173173
};
174174

175-
using namespace CPyCppyy;
176-
177175
#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m))
178176

179177
static int rootmodule_traverse(PyObject *m, visitproc visit, void *arg)
@@ -206,11 +204,5 @@ extern "C" PyObject *PyInit_libROOTPythonizations()
206204
// keep gRootModule, but do not increase its reference count even as it is borrowed,
207205
// or a self-referencing cycle would be created
208206

209-
// Make sure the interpreter is initialized once gROOT has been initialized
210-
TInterpreter::Instance();
211-
212-
// signal policy: don't abort interpreter in interactive mode
213-
CallContext::SetGlobalPolicy(CallContext::kProtected, !gROOT->IsBatch());
214-
215207
return gRootModule;
216208
}

0 commit comments

Comments
 (0)