Traceback on Ctrl-C
- Ctrl-C will print a traceback of all threads instead of complaining
This commit is contained in:
parent
7b9b7504ad
commit
1d87c63504
|
@ -4,6 +4,7 @@ import sys
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from multiprocessing import current_process
|
from multiprocessing import current_process
|
||||||
from threading import current_thread, enumerate
|
from threading import current_thread, enumerate
|
||||||
|
import traceback
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
|
@ -29,10 +30,20 @@ def convertIntToString(n):
|
||||||
else:
|
else:
|
||||||
return unhexlify('0' + a[2:])
|
return unhexlify('0' + a[2:])
|
||||||
|
|
||||||
|
|
||||||
def convertStringToInt(s):
|
def convertStringToInt(s):
|
||||||
return int(hexlify(s), 16)
|
return int(hexlify(s), 16)
|
||||||
|
|
||||||
|
def allThreadTraceback(frame):
|
||||||
|
id2name = dict([(th.ident, th.name) 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):
|
def signal_handler(signal, frame):
|
||||||
logger.error("Got signal %i in %s/%s", signal, current_process().name, current_thread().name)
|
logger.error("Got signal %i in %s/%s", signal, current_process().name, current_thread().name)
|
||||||
if current_process().name == "RegExParser":
|
if current_process().name == "RegExParser":
|
||||||
|
@ -46,6 +57,7 @@ def signal_handler(signal, frame):
|
||||||
if BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'):
|
if BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'):
|
||||||
shutdown.doCleanShutdown()
|
shutdown.doCleanShutdown()
|
||||||
else:
|
else:
|
||||||
|
allThreadTraceback(frame)
|
||||||
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
|
print 'Unfortunately you cannot use Ctrl+C when running the UI because the UI captures the signal.'
|
||||||
|
|
||||||
def isHostInPrivateIPRange(host):
|
def isHostInPrivateIPRange(host):
|
||||||
|
|
Reference in New Issue
Block a user