Commit e98cbf2a authored by Locatelli's avatar Locatelli
Browse files

Review of Lock GIL

Use GIL only for Matplotlib event.
For other the QT layer is deal with
parent a22deda5
......@@ -28,7 +28,6 @@
#include <boost/python/str.hpp>
#include <python3.5/Python.h>
#include "MplLock.h"
#include "Trace.h"
using namespace std;
......@@ -91,8 +90,6 @@ Mpl::~Mpl() {
* close
*/
void Mpl::close() throw (Error) {
MplLock lock;
// Create matplotlib figure object
try {
m_PyPlot.attr("close")();
......@@ -106,8 +103,6 @@ void Mpl::close() throw (Error) {
*/
boost::python::object Mpl::gridSpec(int32 nrows, int32 ncols, const std::vector<int32>& height_ratios,
const std::vector<int32>& width_ratios, float64 wspace, float64 hspace) throw (Error) {
MplLock lock;
auto args = bp::make_tuple(nrows, ncols);
bp::dict kwargs;
if (nrows == 2) {
......@@ -157,8 +152,6 @@ bp::object Mpl::subplot(const bp::object& gridaxis, const bp::dict& keywords) th
* title
*/
void Mpl::title(const std::string& name) throw (Error) {
MplLock lock;
try {
bp::call_method<void, const char *>(m_PyPlot.ptr(), "title", name.c_str());
} catch (...) {
......@@ -170,8 +163,6 @@ void Mpl::title(const std::string& name) throw (Error) {
* title
*/
void Mpl::title(const bp::object& axis, const std::string& name) throw (Error) {
MplLock lock;
try {
bp::call_method<void, const char *>(axis.ptr(), "set_title", name.c_str());
} catch (...) {
......@@ -183,8 +174,6 @@ void Mpl::title(const bp::object& axis, const std::string& name) throw (Error) {
* xlabel
*/
void Mpl::xlabel(const bp::object& axis, const std::string& name) throw (Error) {
MplLock lock;
try {
bp::call_method<void, const char *>(axis.ptr(), "set_xlabel", name.c_str());
} catch (...) {
......@@ -196,8 +185,6 @@ void Mpl::xlabel(const bp::object& axis, const std::string& name) throw (Error)
* ylabel
*/
void Mpl::ylabel(const bp::object& axis, const std::string& name) throw (Error) {
MplLock lock;
try {
bp::call_method<void, const char *>(axis.ptr(), "set_ylabel", name.c_str());
} catch (...) {
......@@ -209,8 +196,6 @@ void Mpl::ylabel(const bp::object& axis, const std::string& name) throw (Error)
* grid
*/
void Mpl::grid(const bp::object& axis, bool show) throw (Error) {
MplLock lock;
bp::tuple args;
if (show == true) {
args = bp::make_tuple(true);
......@@ -229,8 +214,6 @@ void Mpl::grid(const bp::object& axis, bool show) throw (Error) {
* savefig
*/
void Mpl::savefig(const bp::object& figure, const std::string& filename) throw (Error) {
MplLock lock;
auto args = bp::make_tuple(filename);
bp::dict kwargs;
kwargs["format"] = "png";
......@@ -245,7 +228,6 @@ void Mpl::savefig(const bp::object& figure, const std::string& filename) throw (
* get_xlim
*/
std::pair<float64, float64> Mpl::get_xlim(const bp::object& axis) throw (Error) {
MplLock lock;
try {
bp::tuple res(axis.attr("get_xlim")());
float64 min = bp::extract<float64>(res[0]);
......@@ -260,7 +242,6 @@ std::pair<float64, float64> Mpl::get_xlim(const bp::object& axis) throw (Error)
* get_ylim
*/
std::pair<float64, float64> Mpl::get_ylim(const bp::object& axis) throw (Error) {
MplLock lock;
try {
bp::object res = axis.attr("get_ylim")();
float64 min = bp::extract<float64>(res[0]);
......@@ -275,7 +256,6 @@ std::pair<float64, float64> Mpl::get_ylim(const bp::object& axis) throw (Error)
* getCurrentAxis
*/
bp::object Mpl::getCurrentAxis() throw (Error) {
MplLock lock;
try {
bp::object axis = m_PyPlot.attr("gca")();
return axis;
......@@ -288,7 +268,6 @@ bp::object Mpl::getCurrentAxis() throw (Error) {
* selectCurrentAxis
*/
void Mpl::selectCurrentAxis(const bp::object& axis) throw (Error) {
MplLock lock;
try {
auto args = bp::make_tuple(axis);
m_PyPlot.attr("sca")(*args);
......@@ -302,8 +281,6 @@ void Mpl::selectCurrentAxis(const bp::object& axis) throw (Error) {
* set_xdata
*/
void Mpl::set_xdata(const bp::object& line, const std::vector<float64> &x) throw (Error) {
mpl::MplLock lock;
// using numpy arrays
boost::python::list xarray;
for (float64 val : x) {
......@@ -325,8 +302,6 @@ void Mpl::set_xdata(const bp::object& line, const std::vector<float64> &x) throw
* set_ydata
*/
void Mpl::set_ydata(const bp::object& line, const std::vector<float64> &y) throw (Error) {
MplLock lock;
// using numpy arrays
boost::python::list yarray;
for (float64 val : y) {
......@@ -347,7 +322,6 @@ void Mpl::set_ydata(const bp::object& line, const std::vector<float64> &y) throw
* set_xlim
*/
void Mpl::set_xlim(const bp::object& axis, float64 min, float64 max, float64 marge) throw (Error) {
MplLock lock;
float64 tot = max - min;
min -= tot * marge;
max += tot * marge;
......@@ -364,7 +338,6 @@ void Mpl::set_xlim(const bp::object& axis, float64 min, float64 max, float64 mar
* set_ylim
*/
void Mpl::set_ylim(const bp::object& axis, float64 min, float64 max, float64 marge) throw (Error) {
MplLock lock;
float64 tot = max - min;
min -= tot * marge;
max += tot * marge;
......
......@@ -28,7 +28,6 @@
#include <map>
#include <vector>
#include "MplLock.h"
#include "Error.h"
#include "Trace.h"
......
......@@ -22,7 +22,6 @@
#include <boost/python/str.hpp>
#include <boost/python/extract.hpp>
#include "view/mpl/MplLock.h"
#include "Trace.h"
#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
#include <numpy/arrayobject.h>
......@@ -36,8 +35,6 @@ namespace mpl {
* constructor
*/
MplFigure::MplFigure() {
MplLock lock;
// Get Matplotlib Figure
try {
bp::object pymodModule = bp::import(bp::str("matplotlib.pyplot"));
......@@ -80,8 +77,6 @@ MplFigure::~MplFigure() {
* subplots
*/
bp::object MplFigure::subplots() throw (Error) {
MplLock lock;
// Create matplotlib axis object
bp::object axis;
try {
......@@ -96,8 +91,6 @@ bp::object MplFigure::subplots() throw (Error) {
* delaxis
*/
void MplFigure::delaxes(const bp::object& axis) throw (Error) {
MplLock lock;
// delete matplotlib axis object
auto args = bp::make_tuple(axis);
try {
......@@ -111,8 +104,6 @@ void MplFigure::delaxes(const bp::object& axis) throw (Error) {
* draw
*/
void MplFigure::draw() throw (Error) {
MplLock lock;
try {
m_Canvas.attr("draw")();
} catch (...) {
......@@ -124,8 +115,6 @@ void MplFigure::draw() throw (Error) {
* clear
*/
void MplFigure::clear() throw (Error) {
MplLock lock;
try {
m_Figure.attr("clf")();
} catch (...) {
......@@ -137,7 +126,6 @@ void MplFigure::clear() throw (Error) {
* resetToolBarStack
*/
void MplFigure::resetToolBarStack() throw (Error) {
MplLock lock;
try {
m_Toolbar.attr("update")();
} catch (...) {
......@@ -149,7 +137,6 @@ void MplFigure::resetToolBarStack() throw (Error) {
* home
*/
void MplFigure::home() throw (Error) {
MplLock lock;
try {
m_Toolbar.attr("home")();
} catch (...) {
......@@ -161,7 +148,6 @@ void MplFigure::home() throw (Error) {
* back
*/
void MplFigure::back() throw (Error) {
MplLock lock;
try {
m_Toolbar.attr("back")();
} catch (...) {
......@@ -173,7 +159,6 @@ void MplFigure::back() throw (Error) {
* zoom
*/
void MplFigure::zoom(bool on) throw (Error) {
MplLock lock;
try {
bool isOn = (m_Toolbar.attr("mode") == "zoom rect");
if (isOn && on) {
......@@ -193,7 +178,6 @@ void MplFigure::zoom(bool on) throw (Error) {
* pan
*/
void MplFigure::pan(bool on) throw (Error) {
MplLock lock;
try {
bool isOn = (m_Toolbar.attr("mode") == "pan/zoom");
if (isOn && on) {
......@@ -213,8 +197,6 @@ void MplFigure::pan(bool on) throw (Error) {
* filesave
*/
void MplFigure::filesave() throw (Error) {
MplLock lock;
try {
m_Toolbar.attr("save_figure")();
} catch (...) {
......@@ -237,7 +219,6 @@ std::pair<float64, float64> MplFigure::toDataCoord(float64 x, float64 y, int32 d
// matplotlib.backend_bases.LocationEvent where we transform first to
// matplotlib's coordinate system, (0,0) is bottom left,
// and then to the data coordinates
MplLock lock;
const float64 xPosPhysical = x * devicePixelRatio;
// Y=0 is at the bottom
......
......@@ -35,19 +35,19 @@ public:
* \brief constructor, lock the GIL
*/
MplLock() {
m_State = PyGILState_Ensure();
// m_State = PyGILState_Ensure();
}
/*!
* \brief destructor, release the GIL
*/
~MplLock() {
PyGILState_Release(m_State);
// PyGILState_Release(m_State);
}
private:
PyGILState_STATE m_State; //! State of interpreter to get back
// PyGILState_STATE m_State; //! State of interpreter to get back
};
}
......
......@@ -18,7 +18,6 @@
#include "MplPlot1D.h"
#include "MplLock.h"
#include "Trace.h"
#include "plot/PlotType.h"
#include <boost/python/call_method.hpp>
......@@ -94,8 +93,6 @@ void MplPlot1D::legend(const bp::dict& keywords) throw (Error) {
* clear
*/
void MplPlot1D::clear() throw (Error) {
MplLock lock;
try {
m_Axis.attr("clear")();
}
......@@ -115,8 +112,6 @@ void MplPlot1D::grid(bool show) throw (Error) {
* log
*/
void MplPlot1D::log(bool tolog) throw (Error) {
MplLock lock;
string buf;
if (tolog == true) {
buf = "log";
......@@ -171,8 +166,6 @@ void MplPlot1D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
*/
void MplPlot1D::plot(uint32 numplot, const std::vector<float64> &y, bp::dict& keywords) throw (Error)
{
MplLock lock;
// using numpy arrays
boost::python::list yarray;
for(float64 val : y) {
......@@ -202,8 +195,6 @@ void MplPlot1D::plot(uint32 numplot, const std::vector<float64> &y, bp::dict& ke
*/
void MplPlot1D::plot(uint32 numplot, const std::vector<float64> &x, const std::vector<float64> &y, bp::dict& keywords) throw (Error)
{
MplLock lock;
// using numpy arrays
boost::python::list xarray;
for(float64 val : x) {
......@@ -241,8 +232,6 @@ void MplPlot1D::errorbar(uint32 numplot, const std::vector<float64> &y, bp::dict
errorYArrays.resize(y.size());
transform(y.begin(), y.end(), errorYArrays.begin(), [](float64 val) -> float64 {return sqrt(fabs(val));});
MplLock lock;
// using numpy arrays
boost::python::list yarray;
for(float64 val : y) {
......@@ -291,8 +280,6 @@ void MplPlot1D::errorbar(uint32 numplot, const std::vector<float64> &x, const st
errorYArrays.resize(y.size());
transform(y.begin(), y.end(), errorYArrays.begin(), [](float64 val) -> float64 {return sqrt(fabs(val));});
MplLock lock;
// using numpy arrays
boost::python::list xarray;
for(float64 val : x) {
......@@ -342,8 +329,6 @@ void MplPlot1D::errorbar(uint32 numplot, const std::vector<float64> &x, const st
*/
void MplPlot1D::optimizationPlot(uint32 numplot, const std::vector<float64> &x, const std::vector<float64> &y, bp::dict& keywords) throw (Error)
{
MplLock lock;
// using numpy arrays
boost::python::list xarray;
for(float64 val : x) {
......@@ -373,8 +358,6 @@ void MplPlot1D::optimizationPlot(uint32 numplot, const std::vector<float64> &x,
* optimizationResult
*/
void MplPlot1D::optimizationResult(uint32 numplot, float64 &xvalue, bp::dict& keywords) throw (Error) {
MplLock lock;
// Get plot limit
float64 ymin, ymax;
try {
......
......@@ -24,7 +24,6 @@
#include <boost/python/import.hpp>
#include <boost/python/str.hpp>
#include "MplLock.h"
#include "MplFigure.h"
#include "Trace.h"
#include "plot/PlotType.h"
......@@ -40,7 +39,6 @@ namespace mpl {
*/
MplPlot2D::MplPlot2D(Mpl* mpl, MplFigure* figure) :
m_Mpl(mpl), m_MplFigure(figure), m_CursorHorizontal(mpl), m_CursorVertical(mpl) {
MplLock lock;
try {
bp::object widgetsModule = bp::import(bp::str("matplotlib.colors"));
m_NormalNorm = widgetsModule.attr("Normalize")();
......@@ -60,8 +58,6 @@ MplPlot2D::~MplPlot2D() {
* subplots
*/
void MplPlot2D::subplots(plot::PlotWindow* plotwindow, int32 mainindice, int32 projxindice, int32 projyindice, int32 colorbarindice) throw (Error) {
MplLock lock;
// Main 2d plot
bp::dict kwargs;
m_MainAxis = m_Mpl->subplot(m_GridSpec[mainindice], kwargs);
......@@ -145,8 +141,6 @@ void MplPlot2D::ylabel(const std::string& name) throw (Error) {
void MplPlot2D::plot(int32 xsize, int32 ysize, const std::vector<float64>& data, const std::vector<float64>& datax
, const std::vector<float64>& datay, const std::vector<float64>& dataprojx,
const std::vector<float64>& dataprojy) throw (Error) {
MplLock lock;
///////////////////////////////////////////////////////////////////////////////////////
//// Create main image
////
......@@ -329,8 +323,6 @@ void MplPlot2D::plot(int32 xsize, int32 ysize, const std::vector<float64>& data,
* updateplot
*/
void MplPlot2D::updateimage(int32 xsize, int32 ysize, const std::vector<float64>& data) throw (Error) {
MplLock lock;
///////////////////////////////////////////////////////////////////////////////////////
//// Update main image
////
......@@ -411,8 +403,6 @@ void MplPlot2D::grid(bool show) throw (Error) {
* aspectRatio
*/
void MplPlot2D::aspectRatio(float64 ratio) throw (Error) {
MplLock lock;
///////////////////////////////////////////////////////////////////////////////////////
//// set aspect on image
////
......@@ -468,8 +458,6 @@ void MplPlot2D::aspectRatio(float64 ratio) throw (Error) {
* log
*/
void MplPlot2D::log(bool tolog) throw (Error) {
MplLock lock;
string buf;
auto args1 = bp::make_tuple();
if (tolog == true) {
......@@ -505,8 +493,6 @@ void MplPlot2D::log(bool tolog) throw (Error) {
* colorMap
*/
void MplPlot2D::colorMap(const std::string& name) throw (Error) {
MplLock lock;
auto args = bp::make_tuple(name);
try {
m_AxisImage.attr("set_cmap")(*args);
......@@ -519,8 +505,6 @@ void MplPlot2D::colorMap(const std::string& name) throw (Error) {
* colorMap
*/
void MplPlot2D::colorLimits(float64 min, float64 max) throw (Error) {
MplLock lock;
auto args = bp::make_tuple(min, max);
try {
m_AxisImage.attr("set_clim")(*args);
......@@ -536,8 +520,6 @@ void MplPlot2D::colorLimits(float64 min, float64 max) throw (Error) {
* selectCurrentAxis
*/
string MplPlot2D::selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
MplLock lock;
string buf;
try {
float64 height = bp::extract<float64>(m_MplFigure->getFigure().attr("bbox").attr("height"));
......@@ -645,8 +627,6 @@ std::vector<int32> MplPlot2D::getImageBoxLimits() throw (Error) {
*/
bp::object MplPlot2D::plotproj(const bp::object& axis, const std::vector<float64> &y, bp::dict& keywords)
throw (Error) {
MplLock lock;
// using numpy arrays
boost::python::list yarray;
for(float64 val : y) {
......@@ -671,8 +651,6 @@ bp::object MplPlot2D::plotproj(const bp::object& axis, const std::vector<float64
*/
bp::object MplPlot2D::plotproj(const bp::object& axis, const std::vector<float64> &x, const std::vector<float64> &y,
bp::dict& keywords) throw (Error) {
MplLock lock;
// using numpy arrays
boost::python::list xarray;
for(float64 val : x) {
......
......@@ -19,7 +19,6 @@
#include "MplCursor.h"
#include "view/mpl/Mpl.h"
#include "view/mpl/MplLock.h"
#include "Trace.h"
#include <boost/python/dict.hpp>
#include <boost/python/import.hpp>
......@@ -43,8 +42,6 @@ MplCursor::MplCursor(Mpl* mpl) :
* init
*/
void MplCursor::init(const bp::object& axis1) throw (Error) {
MplLock lock;
try {
bp::object widgetsModule = bp::import(bp::str("matplotlib.widgets"));
///////////////////////////////////////////////////////////////////////////////////////
......@@ -70,8 +67,6 @@ void MplCursor::init(const bp::object& axis1) throw (Error) {
*/
void MplCursor::init(const boost::python::object& figcanvas, const boost::python::object& axis1,
const boost::python::object& axis2, bool horizontal) throw (Error) {
MplLock lock;
try {
bp::object widgetsModule = bp::object(bp::handle<>(PyImport_ImportModule("matplotlib.widgets")));
///////////////////////////////////////////////////////////////////////////////////////
......
......@@ -23,7 +23,6 @@
#include <boost/python/call_method.hpp>
#include <boost/python/extract.hpp>
#include "view/mpl/MplLock.h"
#include "view/mpl/MplPlot1D.h"
#include "Trace.h"
......@@ -51,8 +50,6 @@ MplLegend::~MplLegend() {
* legend
*/
void MplLegend::display(const bp::dict& keywords) throw (Error) {
MplLock lock;
// Display legend
auto args = bp::make_tuple();
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment