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())