Resolved pylint warnings and removed allThreadTraceback() entirely

This commit is contained in:
Dmitri Bogomolov 2019-03-06 22:36:34 +02:00
parent f2d3b69bf8
commit c38d250389
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 18 additions and 23 deletions

View File

@ -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.')

View File

@ -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):