summaryrefslogtreecommitdiff
path: root/lib/python.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python.c')
-rw-r--r--lib/python.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/python.c b/lib/python.c
index da6f25e..f857c94 100644
--- a/lib/python.c
+++ b/lib/python.c
@@ -8,6 +8,7 @@
#include "python.h"
cDbTable* Python::globalEventsDb = 0;
+int Python::usages = 0;
int Python::globalNamingMode = 0;
const char* Python::globalTmplExpression = "";
@@ -221,14 +222,16 @@ int Python::init(const char* modulePath)
#if PY_MAJOR_VERSION >= 3
PyImport_AppendInittab("event", &PyInitEvent);
- Py_Initialize(); // initialize the Python interpreter
+ if (!usages) Py_Initialize(); // initialize the Python interpreter
pName = PyUnicode_FromString(file);
#else
- Py_Initialize(); // initialize the Python interpreter
+ if (!usages) Py_Initialize(); // initialize the Python interpreter
Py_InitModule("event", eventMethods);
pName = PyString_FromString(file);
#endif
+ usages++;
+
// add search path for Python modules
if (modulePath)
@@ -272,13 +275,16 @@ int Python::init(const char* modulePath)
int Python::exit()
{
+ usages--;
+
if (pFunc)
Py_XDECREF(pFunc);
if (pModule)
Py_DECREF(pModule);
- Py_Finalize();
+ if (!usages)
+ Py_Finalize();
return success;
}