From 32b0d24be297437cbbad825d9d59566d9e0240e9 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Fri, 22 Jan 2016 14:47:26 +0100 Subject: [PATCH] singleWorker shutdown fix if singleWorker crashed, the thread couldn't be joined. This both makes it so that it doesn't crash, as well as reorders the shutdown sequence so that it is less likely to be triggered. Fixes Bitmessage#549 --- src/class_singleWorker.py | 25 +++++++++++++------------ src/shared.py | 6 +++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index 7c04558b..336c5059 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -71,18 +71,19 @@ class singleWorker(threading.Thread, StoppableThread): self.stop.wait( 10) # give some time for the GUI to start before we start on existing POW tasks. - queryreturn = sqlQuery( - '''SELECT DISTINCT toaddress FROM sent WHERE (status='doingpubkeypow' AND folder='sent')''') - for row in queryreturn: - toaddress, = row - self.requestPubKey(toaddress) - - self.sendMsg() - # just in case there are any pending tasks for msg - # messages that have yet to be sent. - self.sendBroadcast() - # just in case there are any tasks for Broadcasts - # that have yet to be sent. + if shared.shutdown == 0: + queryreturn = sqlQuery( + '''SELECT DISTINCT toaddress FROM sent WHERE (status='doingpubkeypow' AND folder='sent')''') + for row in queryreturn: + toaddress, = row + logger.debug("c: %s", shared.shutdown) + self.requestPubKey(toaddress) + # just in case there are any pending tasks for msg + # messages that have yet to be sent. + self.sendMsg() + # just in case there are any tasks for Broadcasts + # that have yet to be sent. + self.sendBroadcast() while shared.shutdown == 0: command, data = shared.workerQueue.get() diff --git a/src/shared.py b/src/shared.py index 2414945e..2a9c3c48 100644 --- a/src/shared.py +++ b/src/shared.py @@ -396,6 +396,9 @@ def doCleanShutdown(): shutdown = 1 #Used to tell proof of work worker threads and the objectProcessorThread to exit. broadcastToSendDataQueues((0, 'shutdown', 'no data')) objectProcessorQueue.put(('checkShutdownVariable', 'no data')) + for thread in threading.enumerate(): + if thread.isAlive() and isinstance(thread, StoppableThread): + thread.stopThread() knownNodesLock.acquire() UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...')) @@ -430,9 +433,6 @@ def doCleanShutdown(): time.sleep(.25) from class_outgoingSynSender import outgoingSynSender - for thread in threading.enumerate(): - if thread.isAlive() and isinstance(thread, StoppableThread): - thread.stopThread() for thread in threading.enumerate(): if thread is not threading.currentThread() and isinstance(thread, StoppableThread) and not isinstance(thread, outgoingSynSender): logger.debug("Waiting for thread %s", thread.name)