Traceback on Ctrl-C

- Ctrl-C will print a traceback of all threads instead of
This commit is contained in:
Peter Šurda 2017-05-27 19:02:05 +02:00
parent 7b9b7504ad
commit 1d87c63504
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import sys
from binascii import hexlify, unhexlify
from multiprocessing import current_process
from threading import current_thread, enumerate
import traceback
from bmconfigparser import BMConfigParser
from debug import logger
@ -29,10 +30,20 @@ def convertIntToString(n):
return unhexlify('0' + a[2:])
def convertStringToInt(s):
return int(hexlify(s), 16)
def allThreadTraceback(frame):
id2name = dict([(th.ident, for th in 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):
logger.error("Got signal %i in %s/%s", signal, current_process().name, current_thread().name)
if current_process().name == "RegExParser":
@ -46,6 +57,7 @@ def signal_handler(signal, frame):
if BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'):
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
def isHostInPrivateIPRange(host):