Reference client for Bitmessage: a P2P encrypted decentralised communication protocol:
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB

"""shutdown function"""
import os
import Queue
import threading
import time
import shared
import state
from debug import logger
from helper_sql import sqlQuery, sqlStoredProcedure
from inventory import Inventory
from knownnodes import saveKnownNodes
from network import StoppableThread
from queues import (
addressGeneratorQueue, objectProcessorQueue, UISignalQueue, workerQueue)
def doCleanShutdown():
Used to tell all the treads to finish work and exit.
state.shutdown = 1
objectProcessorQueue.put(('checkShutdownVariable', 'no data'))
for thread in threading.enumerate():
if thread.isAlive() and isinstance(thread, StoppableThread):
'Saving the knownNodes list of peers to disk...'))'Saving knownNodes list of peers to disk')
saveKnownNodes()'Done saving knownNodes list of peers to disk')
'Done saving the knownNodes list of peers to disk.'))'Flushing inventory in memory out to disk...')
'Flushing inventory in memory out to disk.'
' This should normally only take a second...'))
# Verify that the objectProcessor has finished exiting. It should have
# incremented the shutdown variable from 1 to 2. This must finish before
# we command the sqlThread to exit.
while state.shutdown == 1:
# 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.
for thread in threading.enumerate():
if (
thread is not threading.currentThread()
and isinstance(thread, StoppableThread)
and != 'SQL'
logger.debug("Waiting for thread %s",
# 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')'Finished flushing inventory.')
# flush queues
for queue in (
workerQueue, UISignalQueue, addressGeneratorQueue,
while True:
except Queue.Empty:
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant?'Clean shutdown complete.')
os._exit(0) # pylint: disable=protected-access
else:'Core shutdown complete.')
for thread in threading.enumerate():
logger.debug('Thread %s still running',