summaryrefslogtreecommitdiff
path: root/src/pyinterp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyinterp.cc')
-rw-r--r--src/pyinterp.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/pyinterp.cc b/src/pyinterp.cc
index 71bbea22..2fecc8c4 100644
--- a/src/pyinterp.cc
+++ b/src/pyinterp.cc
@@ -149,15 +149,30 @@ void python_interpreter_t::initialize()
try {
DEBUG("python.interp", "Initializing Python");
+ // PyImport_AppendInittab docs: "This should be called before Py_Initialize()".
+ PyImport_AppendInittab((const char*)"ledger", PyInit_ledger);
+
// Unbuffer stdio to avoid python output getting stuck in buffer when
// stdout is not a TTY. Normally buffers are flushed by Py_Finalize but
// Boost has a long-standing issue preventing proper shutdown of the
// interpreter with Py_Finalize when embedded.
+#if PY_MINOR_VERSION < 12
Py_UnbufferedStdioFlag = 1;
- // PyImport_AppendInittab docs: "This should be called before Py_Initialize()".
- PyImport_AppendInittab((const char*)"ledger", PyInit_ledger);
-
Py_Initialize();
+#else
+ PyStatus status;
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+ config.buffered_stdio = 0;
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
+ return;
+ }
+ PyConfig_Clear(&config);
+#endif
+
assert(Py_IsInitialized());
hack_system_paths();