-// Copyright (C) 2019-2021 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2019-2024 CEA, EDF, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// Author : Anthony GEAY (EDF R&D)
#include "SALOME_CPythonHelper.hxx"
+#include "PythonCppUtils.hxx"
SALOME_CPythonHelper *SALOME_CPythonHelper::_CPYTHONHELPER_INSTANCE = nullptr;
PyDict_SetItemString(_globals,"socket",socket);
}
+void SALOME_CPythonHelper::allowPythonCallsFromDifferentThread() const
+{
+#if PY_VERSION_HEX < 0x03070000
+ PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/
+#endif
+ PyEval_SaveThread(); /* Release the thread state */
+}
+
void SALOME_CPythonHelper::registerToSalomePiDict(const std::string& processName, long pid) const
{
+ AutoGIL agil;
PyObject *mod(PyImport_ImportModule("addToKillList"));//new value
if(!mod)
return;
std::vector<long> SALOME_CPythonHelper::evalVL(const std::string& pyCode) const
{
+ AutoGIL agil;
PyObject* code(Py_CompileString(pyCode.c_str(),"evalVL.py", Py_eval_input));
PyObject *res(PyEval_EvalCode( code, _globals, _locals));
Py_DECREF(code);
std::string SALOME_CPythonHelper::evalS(const std::string& pyCode) const
{
+ AutoGIL agil;
PyObject* code(Py_CompileString(pyCode.c_str(),"evalS.py", Py_eval_input));
PyObject *res(PyEval_EvalCode( code, _globals, _locals));
Py_DECREF(code);
// _globals is borrowed ref -> do nothing
/*if(_locals){ auto refcount_locals = Py_REFCNT(_locals); }*/
-
+ AutoGIL agil;
Py_XDECREF(_locals);
Py_XDECREF(_pickler);
}