[IMP] kill -SIGQUIT dumps the stack of all threads (forwardport of 2124 chs@openerp.com-20100920165253-esaatbgtvha9jhb9 from 5.0 branch)
bzr revid: chs@openerp.com-20100920165456-vux7ke0nmp8mqvna
This commit is contained in:
parent
8d28fc5a61
commit
2686d36182
|
@ -164,9 +164,6 @@ if tools.config["stop_after_init"]:
|
|||
#----------------------------------------------------------
|
||||
|
||||
LST_SIGNALS = ['SIGINT', 'SIGTERM']
|
||||
if os.name == 'posix':
|
||||
LST_SIGNALS.extend(['SIGUSR1','SIGQUIT'])
|
||||
|
||||
|
||||
SIGNALS = dict(
|
||||
[(getattr(signal, sign), sign) for sign in LST_SIGNALS]
|
||||
|
@ -189,6 +186,26 @@ def handler(signum, _):
|
|||
for signum in SIGNALS:
|
||||
signal.signal(signum, handler)
|
||||
|
||||
|
||||
import threading
|
||||
import traceback
|
||||
def dumpstacks(signum, _):
|
||||
# code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696
|
||||
|
||||
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[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()))
|
||||
|
||||
logger.notifyChannel("dumpstacks", netsvc.LOG_INFO, "\n".join(code))
|
||||
|
||||
if os.name == 'posix':
|
||||
signal.signal(signal.SIGQUIT, dumpstacks)
|
||||
|
||||
if tools.config['pidfile']:
|
||||
fd = open(tools.config['pidfile'], 'w')
|
||||
pidtext = "%d" % (os.getpid())
|
||||
|
|
Loading…
Reference in New Issue