diff --git a/src/octoprint/logging/handlers.py b/src/octoprint/logging/handlers.py index adc079b56..bf7c47992 100644 --- a/src/octoprint/logging/handlers.py +++ b/src/octoprint/logging/handlers.py @@ -16,6 +16,9 @@ class AsyncLogHandlerMixin(logging.Handler): super(AsyncLogHandlerMixin, self).__init__(*args, **kwargs) def emit(self, record): + if getattr(self._executor, "_shutdown", False): + return + try: self._executor.submit(self._emit, record) except Exception: @@ -25,6 +28,10 @@ class AsyncLogHandlerMixin(logging.Handler): # noinspection PyUnresolvedReferences super(AsyncLogHandlerMixin, self).emit(record) + def close(self): + self._executor.shutdown(wait=True) + super(AsyncLogHandlerMixin, self).close() + class CleaningTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler): diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index ff452f398..368b4749f 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -102,6 +102,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, if not self._settings.get_boolean(["enabled"]): return self._track_shutdown() + self._executor.shutdown(wait=True) ##~~ EventHandlerPlugin diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 24b97f809..b31f11597 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -903,6 +903,8 @@ class Server(object): observer.stop() observer.join() eventManager.fire(events.Events.SHUTDOWN) + + self._logger.info("Calling on_shutdown on plugins") octoprint.plugin.call_plugin(octoprint.plugin.ShutdownPlugin, "on_shutdown", sorting_context="ShutdownPlugin.on_shutdown")