Skip to content
Snippets Groups Projects
Commit 59ec9c4d authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Applied clang format Re #23266

parent b5d47cec
No related branches found
No related tags found
No related merge requests found
......@@ -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
#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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment