Merge branch '1214' into v0.6

This commit is contained in:
Peter Šurda 2018-04-11 13:19:53 +02:00
commit 4507464c56
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
5 changed files with 91 additions and 65 deletions

View File

@ -218,10 +218,12 @@ class Main:
sys.exit()
elif opt in ("-d", "--daemon"):
daemon = True
state.enableGUI = False # run without a UI
elif opt in ("-c", "--curses"):
state.curses = True
elif opt in ("-t", "--test"):
state.testmode = daemon = True
state.enableGUI = False # run without a UI
# is the application already running? If yes then exit.
shared.thisapp = singleinstance("", daemon)
@ -241,6 +243,10 @@ class Main:
state.dandelion = 0
helper_bootstrap.knownNodes()
# Not needed if objproc is disabled
if state.enableObjProc:
# Start the address generation thread
addressGeneratorThread = addressGenerator()
addressGeneratorThread.daemon = True # close the main program even if there are threads left
@ -259,6 +265,9 @@ class Main:
Inventory() # init
Dandelion() # init, needs to be early because other thread may access it early
# Enable object processor and SMTP only if objproc enabled
if state.enableObjProc:
# SMTP delivery thread
if daemon and BMConfigParser().safeGet("bitmessagesettings", "smtpdeliver", '') != '':
smtpDeliveryThread = smtpDeliver()
@ -279,9 +288,12 @@ class Main:
singleCleanerThread.daemon = True # close the main program even if there are threads left
singleCleanerThread.start()
# Not needed if objproc disabled
if state.enableObjProc:
shared.reloadMyAddressHashes()
shared.reloadBroadcastSendersForWhichImWatching()
# API is also objproc dependent
if BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
try:
apiNotifyPath = BMConfigParser().get(
@ -297,6 +309,8 @@ class Main:
singleAPIThread.daemon = True # close the main program even if there are threads left
singleAPIThread.start()
# start network components if networking is enabled
if state.enableNetwork:
BMConnectionPool()
asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True
@ -324,8 +338,11 @@ class Main:
import upnp
upnpThread = upnp.uPnPThread()
upnpThread.start()
else:
# Populate with hardcoded value (same as connectToStream above)
state.streamsInWhichIAmParticipating.append(1)
if daemon == False and BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon') == False:
if daemon == False or state.enableGUI: # FIXME redundant?
if state.curses == False:
if not depends.check_pyqt():
sys.exit(

View File

@ -65,7 +65,7 @@ class singleCleaner(threading.Thread, StoppableThread):
# If we are running as a daemon then we are going to fill up the UI
# queue which will never be handled by a UI. We should clear it to
# save memory.
if shared.thisapp.daemon:
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
queues.UISignalQueue.queue.clear()
if timeWeLastClearedInventoryAndPubkeysTables < int(time.time()) - 7380:
timeWeLastClearedInventoryAndPubkeysTables = int(time.time())
@ -120,7 +120,7 @@ class singleCleaner(threading.Thread, StoppableThread):
if "Errno 28" in str(err):
logger.fatal('(while receiveDataThread knownnodes.needToWriteKnownNodesToDisk) Alert: Your disk or data storage volume is full. ')
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
if shared.thisapp.daemon:
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
os._exit(0)
shared.needToWriteKnownNodesToDisk = False

View File

@ -12,6 +12,7 @@ import threading
import traceback
import shared
import state
from debug import logger
import queues
import shutdown
@ -66,7 +67,7 @@ def signal_handler(signal, frame):
"PyBitmessage", "MainThread"):
return
logger.error("Got signal %i", signal)
if shared.thisapp.daemon:
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
shutdown.doCleanShutdown()
else:
allThreadTraceback(frame)

View File

@ -61,7 +61,7 @@ def doCleanShutdown():
except Queue.Empty:
break
if shared.thisapp.daemon:
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
logger.info('Clean shutdown complete.')
shared.thisapp.cleanup()
os._exit(0)

View File

@ -17,6 +17,14 @@ appdata = '' #holds the location of the application data storage directory
shutdown = 0 #Set to 1 by the doCleanShutdown function. Used to tell the proof of work worker threads to exit.
# Component control flags - set on startup, do not change during runtime
# The defaults are for standalone GUI (default operating mode)
enableNetwork = True # enable network threads
enableObjProc = True # enable object processing threads
enableAPI = True # enable API (if configured)
enableGUI = True # enable GUI (QT or ncurses)
enableSTDIO = False # enable STDIO threads
curses = False
sqlReady = False # set to true by sqlTread when ready for processing