diff --git a/src/libpymcr.cpp b/src/libpymcr.cpp index 82a54a6..0fdaf9e 100644 --- a/src/libpymcr.cpp +++ b/src/libpymcr.cpp @@ -26,11 +26,18 @@ namespace libpymcr { return nargout; } - template T evalloop(matlab::cpplib::FutureResult resAsync) { + template T matlab_env::evalloop(matlab::cpplib::FutureResult resAsync) { std::chrono::duration period(1); std::future_status status = resAsync.wait_for(std::chrono::duration(1)); while (status != std::future_status::ready) { status = resAsync.wait_for(period); + // Prints outputs and errors + if(_m_output.get()->in_avail() > 0) { + py::gil_scoped_acquire gil_acquire; + py::print(_m_output.get()->str(), py::arg("flush")=true); + py::gil_scoped_release gil_release; + _m_output.get()->str(std::basic_string()); + } } return resAsync.get(); } @@ -59,8 +66,8 @@ namespace libpymcr { // Re-aquire the GIL py::gil_scoped_acquire gil_acquire; // Prints outputs and errors - if(_m_output.get()->in_avail() > 0) { - py::print(_m_output.get()->str(), py::arg("flush")=true); } + //if(_m_output.get()->in_avail() > 0) { + // py::print(_m_output.get()->str(), py::arg("flush")=true); } if(_m_error.get()->in_avail() > 0) { py::print(_m_error.get()->str(), py::arg("file")=py::module::import("sys").attr("stderr"), py::arg("flush")=true); } // Converts outputs to Python types diff --git a/src/libpymcr.hpp b/src/libpymcr.hpp index fe6097e..d4fd318 100644 --- a/src/libpymcr.hpp +++ b/src/libpymcr.hpp @@ -22,6 +22,7 @@ namespace libpymcr { std::shared_ptr _m_error_buf = std::static_pointer_cast(_m_error); pymat_converter _converter; size_t _parse_inputs(std::vector& m_args, py::args py_args, py::kwargs& py_kwargs); + template T evalloop(matlab::cpplib::FutureResult resAsync); public: py::object feval(const std::u16string &funcname, py::args args, py::kwargs& kwargs); py::object call(py::args args, py::kwargs& kwargs);