Skip to content

Commit

Permalink
Configure Python to run in isolated mode. (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 authored Dec 3, 2023
1 parent cc1bc4c commit ac7009d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/runner/pythonrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ namespace mo2::python {
Py_SetPath(paths.join(';').toStdWString().c_str());
}

Py_OptimizeFlag = 2;
Py_NoSiteFlag = 1;
PyConfig config;
PyConfig_InitIsolatedConfig(&config);

py::initialize_interpreter(false, 1, &argv0);
// from PyBind11
config.parse_argv = 0;
config.install_signal_handlers = 0;

// from MO2
config.site_import = 1;
config.optimization_level = 2;

py::initialize_interpreter(&config, 1, &argv0, true);

if (!Py_IsInitialized()) {
MOBase::log::error(
Expand Down

0 comments on commit ac7009d

Please sign in to comment.