Commit 980cce33 authored by jcarpent's avatar jcarpent
Browse files

[Python] Fix bug in python interpreter

parent 276f184d
// //
// Copyright (c) 2016 CNRS // Copyright (c) 2016,2018 CNRS
// //
// This file is part of Pinocchio // This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it // Pinocchio is free software: you can redistribute it
...@@ -30,17 +30,18 @@ namespace se3 ...@@ -30,17 +30,18 @@ namespace se3
Model buildModel(const std::string & filename, const std::string & model_name, bool verbose) throw (bp::error_already_set) Model buildModel(const std::string & filename, const std::string & model_name, bool verbose) throw (bp::error_already_set)
{ {
Py_Initialize(); Py_Initialize();
bp::object main_module = bp::import("__main__"); bp::object main_module = bp::import("__main__");
// Get a dict for the global namespace to exec further python code with // Get a dict for the global namespace to exec further python code with
bp::dict globals = bp::extract<bp::dict>(main_module.attr("__dict__")); bp::dict globals = bp::extract<bp::dict>(main_module.attr("__dict__"));
// We need to link to the pinocchio PyWrap. We delegate the dynamic loading to the python interpreter. // We need to link to the pinocchio PyWrap. We delegate the dynamic loading to the python interpreter.
bp::object cpp_module( (bp::handle<>(bp::borrowed(PyImport_AddModule("libpinocchio_pywrap")))) );
bp::object cpp_module( (bp::handle<>(PyImport_AddModule("libpinocchio_pywrap"))) );
// That's it, you can exec your python script, starting with a model you // That's it, you can exec your python script, starting with a model you
// can update as you want. // can update as you want.
try { try
{
bp::exec_file((bp::str)filename, globals); bp::exec_file((bp::str)filename, globals);
} }
catch (bp::error_already_set & e) catch (bp::error_already_set & e)
...@@ -64,8 +65,11 @@ namespace se3 ...@@ -64,8 +65,11 @@ namespace se3
std::cout << " degrees of freedom." << std::endl; std::cout << " degrees of freedom." << std::endl;
} }
// Py_Finalize(); // close interpreter
Py_Finalize();
return model; return model;
} }
} // namespace python } // namespace python
} // namespace se3 } // namespace se3
Supports Markdown
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