diff --git a/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h b/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h index 9a2bd79a34f08cfb12a58fff54a579a45a93150f..4a839ffeb32ac262ddcd8c5ec888846406ec70eb 100644 --- a/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h +++ b/Framework/PythonInterface/inc/MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h @@ -11,42 +11,41 @@ namespace Environment { /** * Defines a structure for releaseing the Python GIL - * using the RAII pattern. This releases the Python GIL + * using the RAII pattern. This releases the Python GIL * for the duration of the current scope. */ class PYTHON_KERNEL_DLL ReleaseGlobalInterpreter { public: - /// Default constructor ReleaseGlobalInterpreter(); /// Destructor ~ReleaseGlobalInterpreter(); private: - // Stores the current python trace used to track where in - // a python script you are. + // Stores the current python trace used to track where in + // a python script you are. Py_tracefunc m_tracefunc; PyObject *m_tracearg; /// Saved thread state - PyThreadState *m_saved; + PyThreadState *m_saved; }; ReleaseGlobalInterpreter::ReleaseGlobalInterpreter() - : m_tracefunc(nullptr), m_tracearg(nullptr), m_saved(nullptr) { - PyThreadState *curThreadState = PyThreadState_GET(); - m_tracefunc = curThreadState->c_tracefunc; - m_tracearg = curThreadState->c_traceobj; - Py_XINCREF(m_tracearg); - PyEval_SetTrace(nullptr, nullptr); - m_saved = PyEval_SaveThread(); + : m_tracefunc(nullptr), m_tracearg(nullptr), m_saved(nullptr) { + PyThreadState *curThreadState = PyThreadState_GET(); + m_tracefunc = curThreadState->c_tracefunc; + m_tracearg = curThreadState->c_traceobj; + Py_XINCREF(m_tracearg); + PyEval_SetTrace(nullptr, nullptr); + m_saved = PyEval_SaveThread(); } ReleaseGlobalInterpreter::~ReleaseGlobalInterpreter() { - PyEval_RestoreThread(m_saved); - PyEval_SetTrace(m_tracefunc, m_tracearg); - Py_XDECREF(m_tracearg); + PyEval_RestoreThread(m_saved); + PyEval_SetTrace(m_tracefunc, m_tracearg); + Py_XDECREF(m_tracearg); } -} -} -} \ No newline at end of file +} // namespace Environment +} // namespace PythonInterface +} // namespace Mantid \ No newline at end of file diff --git a/Framework/PythonInterface/mantid/api/src/Exports/FileFinder.cpp b/Framework/PythonInterface/mantid/api/src/Exports/FileFinder.cpp index 0cd74109e6fce0333f71e2373b313cb188e4f9e9..cde58c62f7c32dc51df43ad69735a67389bc40c5 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/FileFinder.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/FileFinder.cpp @@ -1,10 +1,10 @@ #include "MantidAPI/FileFinder.h" #include "MantidKernel/WarningSuppressions.h" +#include "MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h" +#include <Poco/Thread.h> #include <boost/python/class.hpp> #include <boost/python/overloads.hpp> #include <boost/python/reference_existing_object.hpp> -#include "MantidPythonInterface/kernel/Environment/ReleaseGlobalInterpreter.h" -#include <Poco/Thread.h> #include <iostream> using Mantid::API::FileFinder; @@ -26,14 +26,17 @@ GNU_DIAG_ON("unused-local-typedef") /** * Runs FileFinder.findRuns after releasing the python GIL. * @param self :: A reference to the calling object - * @param hinstr :: A string containing the run number and possibly instrument to search for + * @param hinstr :: A string containing the run number and possibly instrument + * to search for */ -std::vector<std::string> runFinderProxy(FileFinderImpl &self, std::string hinstr) { - // Before calling the function we need to release the GIL, +std::vector<std::string> runFinderProxy(FileFinderImpl &self, + std::string hinstr) { + // Before calling the function we need to release the GIL, // drop the Python threadstate and reset anything installed - // via PyEval_SetTrace while we execute the C++ code - ReleaseGlobalInterpreter - // does this for us - Mantid::PythonInterface::Environment::ReleaseGlobalInterpreter releaseGlobalInterpreter; + // via PyEval_SetTrace while we execute the C++ code - + // ReleaseGlobalInterpreter does this for us + Mantid::PythonInterface::Environment::ReleaseGlobalInterpreter + releaseGlobalInterpreter; return self.findRuns(hinstr); }