Skip to content

Commit

Permalink
[PyROOT] Expose gROOT via CPython extension for use in atexit handler
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Nov 11, 2024
1 parent 6973248 commit 6aef770
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bindings/pyroot/pythonizations/python/ROOT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ def cleanup():
facade.__dict__["app"].process_root_events.join()

if "libROOTPythonizations" in sys.modules:
backend = sys.modules["libROOTPythonizations"]

from ROOT import PyConfig

if PyConfig.ShutDown:
# Hard teardown: run part of the gROOT shutdown sequence.
# Running it here ensures that it is done before any ROOT libraries
# are off-loaded, with unspecified order of static object destruction.
facade.gROOT.EndOfProcessCleanups()
backend.gROOT.EndOfProcessCleanups()


atexit.register(cleanup)
7 changes: 7 additions & 0 deletions bindings/pyroot/pythonizations/src/PyROOTModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../../cppyy/CPyCppyy/src/ProxyWrappers.h"

// ROOT
#include "TInterpreter.h"
#include "TROOT.h"
#include "TSystem.h"
#include "RConfigure.h"
Expand Down Expand Up @@ -166,6 +167,12 @@ extern "C" PyObject *PyInit_libROOTPythonizations()
// Memory management
gROOT->GetListOfCleanups()->Add(&GetRegulatorCleanup());

// Bind ROOT globals that will be needed in ROOT.py
PyModule_AddObject(gRootModule, "gROOT", CPyCppyy::Instance_FromVoidPtr(gROOT, "TROOT"));

// Make sure interpreter is initialized now
TInterpreter::Instance();

// signal policy: don't abort interpreter in interactive mode
CallContext::SetGlobalSignalPolicy(!gROOT->IsBatch());

Expand Down

0 comments on commit 6aef770

Please sign in to comment.