🐛 Fix async issue with logging on shutdown

Asynchronous components might be active after on_shutdown, and
AsyncLogHandlerMixin should be able to cope with logs generated by
them.

Closes #3629
This commit is contained in:
Gina Häußge committed 2020-07-06 21:56:43 +02:00
1 parent 20a3700a2c
commit fa148a8b7e
3 files changed
+10

No files matched your search

+7
View File
@@ -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):
@@ -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
+2
View File
@@ -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")