1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Merge pull request #835 from EDCD/fix/834/cease-journal-parse-on-shutdown

Bail out of Journal monitoring during shutdown
This commit is contained in:
Athanasius 2021-01-08 15:14:09 +00:00 committed by GitHub
commit 5776149d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 13 deletions

View File

@ -743,6 +743,10 @@ class AppWindow(object):
'FlightCon': _('Helm'), # Multicrew role 'FlightCon': _('Helm'), # Multicrew role
}.get(role, role) }.get(role, role)
if monitor.thread is None:
logger.debug('monitor.thread is None, assuming shutdown and returning')
return
while True: while True:
entry = monitor.get_entry() entry = monitor.get_entry()
if not entry: if not entry:

View File

@ -1,16 +1,13 @@
import json import json
from calendar import timegm from calendar import timegm
from operator import itemgetter
from os import listdir
from os.path import isdir, isfile, join, getsize from os.path import isdir, isfile, join, getsize
from sys import platform from sys import platform
import time import time
if __debug__:
from traceback import print_exc
from config import config from config import config
from EDMCLogging import get_main_logger
logger = get_main_logger()
if platform=='darwin': if platform=='darwin':
from watchdog.observers import Observer from watchdog.observers import Observer
@ -67,8 +64,10 @@ class Dashboard(FileSystemEventHandler):
if not self.observed and not polling: if not self.observed and not polling:
self.observed = self.observer.schedule(self, self.currentdir) self.observed = self.observer.schedule(self, self.currentdir)
if __debug__: if polling:
print('%s Dashboard "%s"' % (polling and 'Polling' or 'Monitoring', self.currentdir)) logger.debug(f'Polling Dashboard "{self.currentdir}"')
else:
logger.debug(f'Monitoring Dashboard "{self.currentdir}"')
# Even if we're not intending to poll, poll at least once to process pre-existing # Even if we're not intending to poll, poll at least once to process pre-existing
# data and to check whether the watchdog thread has crashed due to events not # data and to check whether the watchdog thread has crashed due to events not
@ -78,8 +77,8 @@ class Dashboard(FileSystemEventHandler):
return True return True
def stop(self): def stop(self):
if __debug__: logger.debug('Stopping monitoring Dashboard')
print('Stopping monitoring Dashboard')
self.currentdir = None self.currentdir = None
if self.observed: if self.observed:
self.observed = None self.observed = None
@ -127,8 +126,8 @@ class Dashboard(FileSystemEventHandler):
self.status != entry): self.status != entry):
self.status = entry self.status = entry
self.root.event_generate('<<DashboardEvent>>', when="tail") self.root.event_generate('<<DashboardEvent>>', when="tail")
except: except Exception:
if __debug__: print_exc() logger.exception('Reading Status.json')
# singleton # singleton
dashboard = Dashboard() dashboard = Dashboard()

View File

@ -187,8 +187,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
return True return True
def stop(self): def stop(self):
if __debug__: logger.debug('Stopping monitoring Journal')
print('Stopping monitoring Journal')
self.currentdir = None self.currentdir = None
self.version = None self.version = None
@ -327,6 +326,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
loghandle.seek(0, SEEK_END) # required to make macOS notice log change over SMB loghandle.seek(0, SEEK_END) # required to make macOS notice log change over SMB
loghandle.seek(log_pos, SEEK_SET) # reset EOF flag # TODO: log_pos reported as possibly unbound loghandle.seek(log_pos, SEEK_SET) # reset EOF flag # TODO: log_pos reported as possibly unbound
for line in loghandle: for line in loghandle:
# Paranoia check to see if we're shutting down
if threading.current_thread() != self.thread:
logger.info("We're not meant to be running, exiting...")
return # Terminate
if b'"event":"Location"' in line: if b'"event":"Location"' in line:
logger.trace('Found "Location" event, appending to event_queue') logger.trace('Found "Location" event, appending to event_queue')
@ -823,6 +827,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
:return: dict representing the event :return: dict representing the event
""" """
if self.thread is None:
logger.debug('Called whilst self.thread is None, returning')
return None
if not self.event_queue: if not self.event_queue:
logger.debug('Called with no event_queue') logger.debug('Called with no event_queue')
return None return None

View File

@ -251,10 +251,14 @@ def notify_stop():
plugin_stop = plugin._get_func('plugin_stop') plugin_stop = plugin._get_func('plugin_stop')
if plugin_stop: if plugin_stop:
try: try:
logger.info(f'Asking plugin "{plugin.name}" to stop...')
newerror = plugin_stop() newerror = plugin_stop()
error = error or newerror error = error or newerror
except Exception as e: except Exception as e:
logger.exception(f'Plugin "{plugin.name}" failed') logger.exception(f'Plugin "{plugin.name}" failed')
logger.info('Done')
return error return error