summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a68d919)
raw | patch | inline | side by side (parent: a68d919)
author | Sven Trenkel <collectd@semidefinite.de> | |
Thu, 26 Jan 2012 11:20:28 +0000 (11:20 +0000) | ||
committer | Sven Trenkel <collectd@semidefinite.de> | |
Thu, 26 Jan 2012 12:35:45 +0000 (12:35 +0000) |
src/python.c | patch | blob | history |
diff --git a/src/python.c b/src/python.c
index d5c2d461576730cab20c7508bf87a8a185774ded..cfc07f6197d2d55a156b83d9ebac016f6ba19153 100644 (file)
--- a/src/python.c
+++ b/src/python.c
static PyThreadState *state;
-static PyObject *cpy_format_exception;
+static PyObject *sys_path, *cpy_format_exception;
static cpy_callback_t *cpy_config_callbacks;
static cpy_callback_t *cpy_init_callbacks;
}
#endif
-static int cpy_config(oconfig_item_t *ci) {
- int i;
+static int cpy_init_python() {
char *argv = "";
- PyObject *sys, *tb;
- PyObject *sys_path;
+ PyObject *sys;
PyObject *module;
-
- /* Ok in theory we shouldn't do initialization at this point
- * but we have to. In order to give python scripts a chance
- * to register a config callback we need to be able to execute
- * python code during the config callback so we have to start
- * the interpreter here. */
- /* Do *not* use the python "thread" module at this point! */
#ifdef IS_PY3K
/* Add a builtin module, before Py_Initialize */
PyModule_AddIntConstant(module, "NOTIF_FAILURE", NOTIF_FAILURE);
PyModule_AddIntConstant(module, "NOTIF_WARNING", NOTIF_WARNING);
PyModule_AddIntConstant(module, "NOTIF_OKAY", NOTIF_OKAY);
+ return 0;
+}
+
+static int cpy_config(oconfig_item_t *ci) {
+ int i;
+ PyObject *tb;
+
+ /* Ok in theory we shouldn't do initialization at this point
+ * but we have to. In order to give python scripts a chance
+ * to register a config callback we need to be able to execute
+ * python code during the config callback so we have to start
+ * the interpreter here. */
+ /* Do *not* use the python "thread" module at this point! */
+
+ if (!Py_IsInitialized() && cpy_init_python()) return 1;
+
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
WARNING("python plugin: Ignoring unknown config key \"%s\".", item->key);
}
}
- Py_DECREF(sys_path);
return 0;
}