From ac7009d17f711b8adce1a3705136b2447cac7cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 3 Dec 2023 09:15:57 +0100 Subject: [PATCH] Configure Python to run in isolated mode. (#121) --- src/runner/pythonrunner.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 8c190b9..54f4019 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -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(