Python babeltrace docs: Add missing sphinx dist file
[babeltrace.git] / python-plugin-provider / python-plugin-provider.c
index a07e187f7ddb95c2226f11110c35822df3e02f7b..2404fc7acbdb434064758faa51b88ec2231dd488 100644 (file)
@@ -25,7 +25,7 @@
  */
 
 #define BT_LOG_TAG "PLUGIN-PY"
-#include <babeltrace/lib-logging-internal.h>
+#include "logging.h"
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler-internal.h>
@@ -57,6 +57,7 @@ enum python_state {
 } python_state = PYTHON_STATE_NOT_INITED;
 
 static PyObject *py_try_load_plugin_module_func = NULL;
+static bool python_was_initialized_by_us;
 
 static
 void print_python_traceback_warn(void)
@@ -99,9 +100,14 @@ void init_python(void)
        }
 
        if (!Py_IsInitialized()) {
+               BT_LOGI_STR("Python interpreter is not initialized: initializing Python interpreter.");
                Py_InitializeEx(0);
+               python_was_initialized_by_us = true;
                BT_LOGI("Initialized Python interpreter: version=\"%s\"",
                        Py_GetVersion());
+       } else {
+               BT_LOGI("Python interpreter is already initialized: version=\"%s\"",
+                       Py_GetVersion());
        }
 
        py_bt2_py_plugin_mod = PyImport_ImportModule("bt2.py_plugin");
@@ -134,7 +140,7 @@ end:
 
 __attribute__((destructor)) static
 void fini_python(void) {
-       if (Py_IsInitialized()) {
+       if (Py_IsInitialized() && python_was_initialized_by_us) {
                if (py_try_load_plugin_module_func) {
                        Py_DECREF(py_try_load_plugin_module_func);
                        py_try_load_plugin_module_func = NULL;
This page took 0.024117 seconds and 4 git commands to generate.