From 870ba570f466576e019ea1c13d6857da733a6eb0 Mon Sep 17 00:00:00 2001 From: Ben Frederickson Date: Sun, 5 Aug 2018 13:17:00 -0700 Subject: [PATCH] Don't write out debug messages on shutdown When the python intrpreter exits, any attempts to log messages into it throw an exception. Rather than writing these spurious error messages out, just write out the log message using the default stderrlogger (if it's not a debug message). --- python_bindings/nmslib.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python_bindings/nmslib.cc b/python_bindings/nmslib.cc index 3f95536..77e96af 100644 --- a/python_bindings/nmslib.cc +++ b/python_bindings/nmslib.cc @@ -412,10 +412,12 @@ class PythonLogger inner.attr("critical")(message); break; } - } catch (const std::exception & e) { - std::cerr << "Failed to log '" << message << "'. Exception:" << e.what() << std::endl; } catch (...) { - std::cerr << "Failed to log '" << message << "'" << std::endl; + // This is almost certainly due to python process shut down. + // Just write the message out to stderr if its not a debug message + if (severity != LIB_DEBUG) { + StdErrLogger().log(severity, file, line, function, message); + } } } };