From 5da9e786e493542c18a2f5631242802fd84ff2c6 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Fri, 29 Mar 2024 17:51:17 -0400 Subject: [PATCH] BUG: Fixed issue with failing print causing filter to fail (#899) This is a temporary band aid to fix an exception being thrown from python when running through DREAM3D-NX on Windows because std::cout is disabled. Signed-off-by: Jared Duffey --- wrapping/python/CxPybind/CxPybind/CxPybind.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wrapping/python/CxPybind/CxPybind/CxPybind.hpp b/wrapping/python/CxPybind/CxPybind/CxPybind.hpp index 755c6982b3..28c87f85ca 100644 --- a/wrapping/python/CxPybind/CxPybind/CxPybind.hpp +++ b/wrapping/python/CxPybind/CxPybind/CxPybind.hpp @@ -376,7 +376,15 @@ std::string MakePythonSignature(std::string_view funcName, const Internals& inte inline void PyPrintMessage(const IFilter::Message& message) { py::gil_scoped_acquire acquireGIL{}; - py::print(fmt::format("{}", message.message)); + try + { + py::print(fmt::format("{}", message.message)); + } catch(const py::error_already_set& pyException) + { + // Can fail when called in a program without stdout (i.e. GUI on Windows) + // Catch the exception to prevent the filter execution from failing + // Should be replaced with the ability to pass in a message handler to the python execute + } } inline IFilter::MessageHandler CreatePyMessageHandler()