From 2686d36182655d1f1ef4bd6ee8673f2aef5f56d6 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 20 Sep 2010 18:54:56 +0200 Subject: [PATCH] [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 --- bin/openerp-server.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/openerp-server.py b/bin/openerp-server.py index 92e945acda0..f03c64d3400 100755 --- a/bin/openerp-server.py +++ b/bin/openerp-server.py @@ -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())