From 1b921a718cc06ea7e49f4085650f60ac2c50e5dd Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Thu, 28 Sep 2017 18:10:03 +0300 Subject: [PATCH 1/3] Check daemon status in singleinstance instead of config --- src/helper_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helper_generic.py b/src/helper_generic.py index 4f7a1299..588ae8f1 100644 --- a/src/helper_generic.py +++ b/src/helper_generic.py @@ -6,7 +6,7 @@ from multiprocessing import current_process from threading import current_thread, enumerate import traceback -from bmconfigparser import BMConfigParser +import shared from debug import logger import queues import shutdown @@ -54,7 +54,7 @@ def signal_handler(signal, frame): if current_thread().name not in ("PyBitmessage", "MainThread"): return logger.error("Got signal %i", signal) - if BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'): + if shared.thisapp.daemon: shutdown.doCleanShutdown() else: allThreadTraceback(frame) -- 2.45.1 From 0c4d4de82fb8f57fd488beee35181b2a08c7e5e6 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sun, 1 Oct 2017 18:39:35 +0300 Subject: [PATCH 2/3] Changed the daemon check approach in other places, where it makes sense --- src/class_singleCleaner.py | 2 +- src/shutdown.py | 3 +-- src/tr.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index bec1a11d..ed0ee044 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -66,7 +66,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 BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'): + if shared.thisapp.daemon: queues.UISignalQueue.queue.clear() if timeWeLastClearedInventoryAndPubkeysTables < int(time.time()) - 7380: timeWeLastClearedInventoryAndPubkeysTables = int(time.time()) diff --git a/src/shutdown.py b/src/shutdown.py index 49c2fb9b..f447148b 100644 --- a/src/shutdown.py +++ b/src/shutdown.py @@ -3,7 +3,6 @@ import Queue import threading import time -from bmconfigparser import BMConfigParser from debug import logger from helper_sql import sqlQuery, sqlStoredProcedure from helper_threading import StoppableThread @@ -60,7 +59,7 @@ def doCleanShutdown(): except Queue.Empty: break - if BMConfigParser().safeGetBoolean('bitmessagesettings','daemon'): + if shared.thisapp.daemon: logger.info('Clean shutdown complete.') shared.thisapp.cleanup() os._exit(0) diff --git a/src/tr.py b/src/tr.py index c185690c..19c234a1 100644 --- a/src/tr.py +++ b/src/tr.py @@ -1,6 +1,6 @@ import os -from bmconfigparser import BMConfigParser +import shared # This is used so that the translateText function can be used when we are in daemon mode and not using any QT functions. class translateClass: @@ -17,7 +17,7 @@ def _translate(context, text, disambiguation = None, encoding = None, n = None): return translateText(context, text, n) def translateText(context, text, n = None): - if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'): + if not shared.thisapp.daemon: try: from PyQt4 import QtCore, QtGui except Exception as err: -- 2.45.1 From 460107abaa05cf0bfb51098e68c868171a0d57b0 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 7 Oct 2017 15:50:25 +0300 Subject: [PATCH 3/3] Handled AttributeError when tr imported from plugin --- src/tr.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tr.py b/src/tr.py index 19c234a1..cf7f16ac 100644 --- a/src/tr.py +++ b/src/tr.py @@ -17,7 +17,11 @@ def _translate(context, text, disambiguation = None, encoding = None, n = None): return translateText(context, text, n) def translateText(context, text, n = None): - if not shared.thisapp.daemon: + try: + is_daemon = shared.thisapp.daemon + except AttributeError: # inside the plugin + is_daemon = False + if not is_daemon: try: from PyQt4 import QtCore, QtGui except Exception as err: -- 2.45.1