[icinga-checkins] icinga.org: icinga2/master: Python: Fix --disable-shared.

git at icinga.org git at icinga.org
Sat Feb 16 12:36:55 CET 2013


Module: icinga2
Branch: master
Commit: 7cb67afaae34030da32412da10aeefe39d9ee555
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=7cb67afaae34030da32412da10aeefe39d9ee555

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Feb 16 12:36:25 2013 +0100

Python: Fix --disable-shared.

---

 lib/python/pythonlanguage.cpp |   12 +++++++++++-
 lib/python/pythonlanguage.h   |    4 ++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp
index d5b832e..3ea81bd 100644
--- a/lib/python/pythonlanguage.cpp
+++ b/lib/python/pythonlanguage.cpp
@@ -31,8 +31,14 @@ PyMethodDef PythonLanguage::m_NativeMethodDef[] = {
 };
 
 PythonLanguage::PythonLanguage(void)
-	: ScriptLanguage()
+	: ScriptLanguage(), m_Initialized(false)
+{ }
+
+void PythonLanguage::InitializeOnce(void)
 {
+	if (m_Initialized)
+		return;
+
 	Py_Initialize();
 	PyEval_InitThreads();
 
@@ -59,6 +65,8 @@ PythonLanguage::PythonLanguage(void)
 
 	ScriptFunction::OnRegistered.connect(boost::bind(&PythonLanguage::RegisterNativeFunction, this, _1, _2));
 	ScriptFunction::OnUnregistered.connect(boost::bind(&PythonLanguage::UnregisterNativeFunction, this, _1));
+
+	m_Initialized = true;
 }
 
 PythonLanguage::~PythonLanguage(void)
@@ -70,6 +78,8 @@ PythonLanguage::~PythonLanguage(void)
 
 ScriptInterpreter::Ptr PythonLanguage::CreateInterpreter(const Script::Ptr& script)
 {
+	InitializeOnce();
+
 	return boost::make_shared<PythonInterpreter>(GetSelf(), script);
 }
 
diff --git a/lib/python/pythonlanguage.h b/lib/python/pythonlanguage.h
index 099c0e4..fc92ff2 100644
--- a/lib/python/pythonlanguage.h
+++ b/lib/python/pythonlanguage.h
@@ -50,7 +50,9 @@ public:
 	static Value MarshalFromPython(PyObject *value);
 
 	String ExceptionInfoToString(PyObject *type, PyObject *exc, PyObject *tb) const;
+
 private:
+	bool m_Initialized;
 	PyThreadState *m_MainThreadState;
 	PyObject *m_NativeModule;
 	PyObject *m_TracebackModule;
@@ -63,6 +65,8 @@ private:
 	static PyObject *PyRegisterFunction(PyObject *self, PyObject *args);
 
 	static PyMethodDef m_NativeMethodDef[];
+
+	void InitializeOnce(void);
 };
 
 }





More information about the icinga-checkins mailing list