Skip to content

[Python] Move the PyROOT application setup to Python - #23699

Merged
guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:pyroot_application_py
Oct 13, 2026
Merged

guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:pyroot_application_py

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

More detail in the commit descriptions.

PyROOT turns ROOT warnings into Python warnings with an error handler in
its CPython extension module. It must not take the GIL while ROOT runs
multithreaded: the reporting thread may hold ROOT's lock, which a thread
holding the GIL may be waiting for. That check has to run before any
Python code, so it can't move to Python with the rest of the handler.

SetWarningHandler() installs an error handler that does the check and
passes warnings to a plain function pointer. The handler returns whether
it took the warning, so the Python bindings can decline one while a
Python exception is pending; declined warnings go to DefaultErrorHandler()
like every other message.

🤖 Done with the help of AI
RPyROOTApplication.cxx created the TApplication from the command line
options, set up ROOT globals, and installed the error handler that turns
ROOT warnings into Python warnings and the PyOS_InputHook that processes
GUI events while the Python prompt waits for input.

The TApplication is now constructed in _application.py through cppyy,
with the same options from sys.argv; its constructor already saves the
interpreter context, which the subclass did a second time. Of the ROOT
globals only gBenchmark still needs setting: TROOT builds gStyle and
TApplication sets gProgName, and evaluating gStyle created the proxies
of TStyle and its base classes during every import.

The warning handler and the input hook stay compiled, in
PyROOTModule.cxx:

- a Python callable passed to ROOT::Internal::SetWarningHandler() makes
  cppyy compile a trampoline during every import, which parses Python.h
  and takes half a second. The handler now declines warnings while a
  Python exception is pending, e.g. after a previous warning turned into
  an error in the same C++ call: PyErr_WarnExplicit() then replaced the
  exception with a SystemError.

- a ctypes callback as input hook swallows the KeyboardInterrupt of a
  Ctrl-C arriving while it runs, so the Ctrl-C is lost.

The setup runs while the ROOT module is being set up, so it goes through
cppyy.gbl rather than the ROOT module, and the pythonization decorator
test excludes the classes it now creates proxies of.

🤖 Done with the help of AI

@vepadulano vepadulano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! See one minor comment.

Comment thread bindings/pyroot/pythonizations/python/ROOT/_application.py
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Test Results

    24 files      24 suites   4d 3h 54m 51s ⏱️
 3 886 tests  3 885 ✅ 0 💤 1 ❌
83 180 runs  83 179 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit 51efb9c.

♻️ This comment has been updated with latest results.

@guitargeek
guitargeek merged commit c573405 into root-project:master Oct 13, 2026
62 of 67 checks passed
@guitargeek
guitargeek deleted the pyroot_application_py branch October 13, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants