From c38d25038908b6baee42f65795dea23e1b5fed28 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 6 Mar 2019 22:36:34 +0200 Subject: [PATCH] Resolved pylint warnings and removed allThreadTraceback() entirely --- src/bitmessagemain.py | 34 ++++++++++++++-------------------- src/bitmessageqt/__init__.py | 7 ++++--- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 3279a67b..e7daf583 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -153,25 +153,13 @@ def _fixSocket(): socket.IPV6_V6ONLY = 27 -def allThreadTraceback(frame): - id2name = dict([(th.ident, th.name) for th in threading.enumerate()]) - code = [] - for threadId, stack in sys._current_frames().items(): - code.append( - '\n# Thread: %s(%d)' % (id2name.get(threadId, ''), threadId)) - for filename, lineno, name, line in traceback.extract_stack(stack): - code.append( - 'File: "%s", line %d, in %s' % (filename, lineno, name)) - if line: - code.append(' %s' % (line.strip())) - print('\n'.join(code)) - - -def signal_handler(signal, frame): +def signal_handler(signum, frame): + """Single handler for any signal sent to pybitmessage""" process = multiprocessing.current_process() + thread = threading.current_thread() logger.error( 'Got signal %i in %s/%s', - signal, process.name, threading.current_thread().name + signum, process.name, thread.name ) if process.name == "RegExParser": # on Windows this isn't triggered, but it's fine, @@ -179,13 +167,19 @@ def signal_handler(signal, frame): raise SystemExit if "PoolWorker" in process.name: raise SystemExit - if threading.current_thread().name not in ("PyBitmessage", "MainThread"): + if thread.name not in ("PyBitmessage", "MainThread"): return - logger.error("Got signal %i", signal) - if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant? + logger.error("Got signal %i", signum) + # there are possible non-UI variants to run bitmessage which should shutdown + # especially test-mode + if shared.thisapp.daemon or not state.enableGUI: shutdown.doCleanShutdown() else: - allThreadTraceback(frame) + print('# Thread: %s(%d)' % (thread.name, thread.ident)) + for filename, lineno, name, line in traceback.extract_stack(frame): + print('File: "%s", line %d, in %s' % (filename, lineno, name)) + if line: + print(' %s' % line.strip()) print('Unfortunately you cannot use Ctrl+C when running the UI' ' because the UI captures the signal.') diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 8267e1f5..0d4cebb3 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -109,14 +109,15 @@ def change_translation(newlocale): # TODO: rewrite def powQueueSize(): - curWorkerQueue = queues.workerQueue.qsize() + """Returns the size of queues.workerQueue including current unfinished work""" + queue_len = queues.workerQueue.qsize() for thread in threading.enumerate(): try: if thread.name == "singleWorker": - curWorkerQueue += thread.busy + queue_len += thread.busy except Exception as err: logger.info('Thread error %s', err) - return curWorkerQueue + return queue_len class MyForm(settingsmixin.SMainWindow):