Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/cpyrt/API.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ static bool Initialize() {
<< std::endl;
return false;
}
}

// force loading of the cppjit module
PyRun_SimpleString(const_cast<char*>("import cppjit"));
// Importing the extension module is what runs the cpyrt initialization
// that sets gThisModule.
if (!cpyrt::gThisModule) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we open an issue tracking the progress of removing global state?

@guitargeek guitargeek Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sure, please go ahead! Would be useful if the issue said which globals you have in mind (gThisModule, gPyTypeMap, gMainDict, the PyString globals? ..) and what problem they cause (subinterpreters, teardown, etc.), so it's actionable rather than a general cleanup item. Because in general, global "immortal" state is not an anti-pattern in CPython.

PyObject* cppjitmod = PyImport_ImportModule("cppjit");
if (!cppjitmod)
return false;
Py_DECREF(cppjitmod);
}

if (!gMainDict) {
Expand Down
Loading