X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=python-plugin-provider%2Fpython-plugin-provider.c;h=9044d8a23f1ed373e1eb343438710e30d0caf637;hb=872eeccbe6bb5201177a77f5bedc216750abd293;hp=a07e187f7ddb95c2226f11110c35822df3e02f7b;hpb=9e0bf9b090e91a5d0c7c221151e77581bb25ce81;p=babeltrace.git diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index a07e187f..9044d8a2 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -25,7 +25,7 @@ */ #define BT_LOG_TAG "PLUGIN-PY" -#include +#include "logging.h" #include #include @@ -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) @@ -80,7 +81,9 @@ void init_python(void) { PyObject *py_bt2_py_plugin_mod = NULL; const char *dis_python_env; +#ifndef __MINGW32__ sighandler_t old_sigint = signal(SIGINT, SIG_DFL); +#endif if (python_state != PYTHON_STATE_NOT_INITED) { goto end; @@ -99,9 +102,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"); @@ -122,9 +130,11 @@ void init_python(void) python_state = PYTHON_STATE_FULLY_INITIALIZED; end: +#ifndef __MINGW32__ if (old_sigint != SIG_ERR) { (void) signal(SIGINT, old_sigint); } +#endif print_python_traceback_warn(); pyerr_clear(); @@ -134,7 +144,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;