summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel M. Pelt <D.M.Pelt@cwi.nl>2015-08-10 17:08:34 +0200
committerDaniel M. Pelt <D.M.Pelt@cwi.nl>2015-08-10 17:08:34 +0200
commit0d5947a0e8e7d6f86c7591a96d877dfe14b187e4 (patch)
treef4ae512e28992b27d68eca681f7d5e0e0aec1cf7
parentab980d9f088c0f4e28d61b94c32788c30a9c4cb9 (diff)
downloadastra-0d5947a0e8e7d6f86c7591a96d877dfe14b187e4.tar.gz
astra-0d5947a0e8e7d6f86c7591a96d877dfe14b187e4.tar.bz2
astra-0d5947a0e8e7d6f86c7591a96d877dfe14b187e4.tar.xz
astra-0d5947a0e8e7d6f86c7591a96d877dfe14b187e4.zip
Ensure we have acquired the GIL before calling Python plugin 'run' method
-rw-r--r--src/PluginAlgorithm.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/PluginAlgorithm.cpp b/src/PluginAlgorithm.cpp
index 4066e30..e79c77b 100644
--- a/src/PluginAlgorithm.cpp
+++ b/src/PluginAlgorithm.cpp
@@ -112,12 +112,14 @@ bool CPluginAlgorithm::initialize(const Config& _cfg){
void CPluginAlgorithm::run(int _iNrIterations){
if(instance==NULL) return;
+ PyGILState_STATE state = PyGILState_Ensure();
PyObject *retVal = PyObject_CallMethod(instance, "run", "i",_iNrIterations);
if(retVal==NULL){
logPythonError();
- return;
+ }else{
+ Py_DECREF(retVal);
}
- Py_DECREF(retVal);
+ PyGILState_Release(state);
}
void fixLapackLoading(){
@@ -147,7 +149,10 @@ void fixLapackLoading(){
}
CPluginAlgorithmFactory::CPluginAlgorithmFactory(){
- Py_Initialize();
+ if(!Py_IsInitialized()){
+ Py_Initialize();
+ PyEval_InitThreads();
+ }
#ifndef _MSC_VER
if(astra::running_in_matlab) fixLapackLoading();
#endif