summaryrefslogtreecommitdiff
path: root/openerp/cli/server.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2013-11-07 17:34:19 +0100
committerChristophe Simonis <chs@openerp.com>2013-11-07 17:34:19 +0100
commit44eab2cfed4f835a698d4722cc11bcf4afc61b7b (patch)
tree8bbf06c43735f188149554243c5bdc281c07e7bf /openerp/cli/server.py
parenta48e79335509f96f9dd386b8ca08f6f7de494f52 (diff)
[IMP] dumpstack dumps greenlets when running in evented mode
bzr revid: chs@openerp.com-20131107163419-90pd7uai8fm70sv9
Diffstat (limited to 'openerp/cli/server.py')
-rw-r--r--openerp/cli/server.py43
1 files changed, 30 insertions, 13 deletions
diff --git a/openerp/cli/server.py b/openerp/cli/server.py
index fc1bf61b617..9d3610f9245 100644
--- a/openerp/cli/server.py
+++ b/openerp/cli/server.py
@@ -166,22 +166,39 @@ def signal_handler(sig, frame):
def dumpstacks(sig, frame):
""" Signal handler: dump a stack trace for each existing thread."""
- # code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696
- # modified for python 2.5 compatibility
- threads_info = dict([(th.ident, {'name': th.name,
- 'uid': getattr(th,'uid','n/a')})
- for th in threading.enumerate()])
code = []
- for threadId, stack in sys._current_frames().items():
- thread_info = threads_info.get(threadId)
- code.append("\n# Thread: %s (id:%s) (uid:%s)" % \
- (thread_info and thread_info['name'] or 'n/a',
- threadId,
- thread_info and thread_info['uid'] or 'n/a'))
+
+ def extract_stack(stack):
for filename, lineno, name, line in traceback.extract_stack(stack):
- code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
+ yield 'File: "%s", line %d, in %s' % (filename, lineno, name)
if line:
- code.append(" %s" % (line.strip()))
+ yield " %s" % (line.strip(),)
+
+ if openerp.evented:
+ # code from http://stackoverflow.com/questions/12510648/in-gevent-how-can-i-dump-stack-traces-of-all-running-greenlets
+ import gc
+ from greenlet import greenlet
+ for ob in gc.get_objects():
+ if not isinstance(ob, greenlet) or not ob:
+ continue
+ code.append("\n# Greenlet: %r" % (ob,))
+ for line in extract_stack(ob.gr_frame):
+ code.append(line)
+
+ else:
+ # code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696
+ # modified for python 2.5 compatibility
+ threads_info = dict([(th.ident, {'name': th.name, 'uid': getattr(th, 'uid', 'n/a')})
+ for th in threading.enumerate()])
+ for threadId, stack in sys._current_frames().items():
+ thread_info = threads_info.get(threadId)
+ code.append("\n# Thread: %s (id:%s) (uid:%s)" %
+ (thread_info and thread_info['name'] or 'n/a',
+ threadId,
+ thread_info and thread_info['uid'] or 'n/a'))
+ for line in extract_stack(stack):
+ code.append(line)
+
_logger.info("\n".join(code))
def setup_signal_handlers(signal_handler):