Python plugin provider: only finalize interpreter if we initialized it
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 17 Aug 2017 00:54:30 +0000 (20:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 17 Sep 2017 18:10:50 +0000 (14:10 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
python-plugin-provider/python-plugin-provider.c

index 2cb5a7334f82169b608d557180875e9f619dd3ec..2404fc7acbdb434064758faa51b88ec2231dd488 100644 (file)
@@ -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)
@@ -101,6 +102,7 @@ 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 {
@@ -138,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.025279 seconds and 4 git commands to generate.