From 54c37150e033446add22d69ce108f19d37f77e86 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 5 Apr 2018 12:36:02 +0200 Subject: [PATCH] Shutdown fixes - tell sql thread to finish only after the other threads finished - prevents other threads stalling on sql replies --- src/shutdown.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/shutdown.py b/src/shutdown.py index f447148b..814362ca 100644 --- a/src/shutdown.py +++ b/src/shutdown.py @@ -35,22 +35,24 @@ def doCleanShutdown(): while state.shutdown == 1: time.sleep(.1) - # This one last useless query will guarantee that the previous flush committed and that the - # objectProcessorThread committed before we close the program. - sqlQuery('SELECT address FROM subscriptions') - logger.info('Finished flushing inventory.') - sqlStoredProcedure('exit') - # Wait long enough to guarantee that any running proof of work worker threads will check the # shutdown variable and exit. If the main thread closes before they do then they won't stop. time.sleep(.25) for thread in threading.enumerate(): - if thread is not threading.currentThread() and isinstance(thread, StoppableThread): + if (thread is not threading.currentThread() and + isinstance(thread, StoppableThread) and + thread.name != 'SQL'): logger.debug("Waiting for thread %s", thread.name) thread.join() - # flush queued + # This one last useless query will guarantee that the previous flush committed and that the + # objectProcessorThread committed before we close the program. + sqlQuery('SELECT address FROM subscriptions') + logger.info('Finished flushing inventory.') + sqlStoredProcedure('exit') + + # flush queues for queue in (workerQueue, UISignalQueue, addressGeneratorQueue, objectProcessorQueue): while True: try: