@@ -103,7 +103,8 @@ class PythonEnvironmentData
103103
104104 std::set<std::string> addedPath;
105105
106- py::module m_sofamodule ;
106+ py::module m_sofaModule ;
107+ py::module m_sofaRuntimeModule ;
107108private:
108109 std::vector<wchar_t *> m_argv;
109110};
@@ -237,7 +238,8 @@ void PythonEnvironment::Init()
237238 // Lastly, we (try to) add modules from the root of SOFA
238239 addPythonModulePathsFromDirectory ( Utils::getSofaPathPrefix () );
239240
240- getStaticData ()->m_sofamodule = py::module::import (" Sofa" );
241+ getStaticData ()->m_sofaModule = py::module::import (" Sofa" );
242+ getStaticData ()->m_sofaRuntimeModule = py::module::import (" SofaRuntime" );
241243 PyRun_SimpleString (" import SofaRuntime" );
242244
243245 // python livecoding related
@@ -508,22 +510,15 @@ std::string PythonEnvironment::getStackAsString()
508510
509511std::string PythonEnvironment::getPythonCallingPointString ()
510512{
511- return py::cast<std::string>(getStaticData ()->m_sofamodule .attr (" getPythonCallingPointAsString" )());
513+ gil lock;
514+ return py::cast<std::string>(getStaticData ()->m_sofaModule .attr (" getPythonCallingPointAsString" )());
512515}
513516
514517sofa::helper::logging::FileInfo::SPtr PythonEnvironment::getPythonCallingPointAsFileInfo ()
515518{
516- PyObject* pDict = PyModule_GetDict (PyImport_AddModule (" SofaRuntime" ));
517- PyObject* res = PyDict_GetItemString (pDict, " getPythonCallingPoint" );
518- if (res && PySequence_Check (res) ){
519- PyObject* filename = PySequence_GetItem (res, 0 ) ;
520- PyObject* number = PySequence_GetItem (res, 1 ) ;
521- std::string tmp=PyBytes_AsString (filename);
522- auto lineno = PyLong_AsLong (number);
523- Py_DECREF (res) ;
524- return SOFA_FILE_INFO_COPIED_FROM (tmp, lineno);
525- }
526- return SOFA_FILE_INFO_COPIED_FROM (" undefined" , -1 );
519+ gil lock;
520+ py::tuple cp = getStaticData ()->m_sofaRuntimeModule .attr (" getPythonCallingPoint" )();
521+ return SOFA_FILE_INFO_COPIED_FROM (py::cast<std::string>(cp[0 ]), py::cast<int >(cp[1 ]));
527522}
528523
529524void PythonEnvironment::setArguments (const std::string& filename, const std::vector<std::string>& arguments)
0 commit comments