[IMP] tools.dumpstack: show extra thread info

By using the thread's repr() we get its type, name, daemon status and
ID, all at one time. No need to include them separately.

Fall back to the threadId in case the repr() is empty, which can
happen for exotic threads (the gevent main thread seems to be like that)
This commit is contained in:
Olivier Dony
2017-09-25 11:22:09 +02:00
parent bbcd49df6b
commit be59d0b85c
+3 -4
View File
@@ -904,16 +904,15 @@ def dumpstacks(sig=None, frame=None):
# 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 = {th.ident: {'name': th.name,
threads_info = {th.ident: {'repr': repr(th),
'uid': getattr(th, 'uid', 'n/a'),
'dbname': getattr(th, 'dbname', 'n/a'),
'url': getattr(th, 'url', '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) (db:%s) (uid:%s) (url:%s)" %
(thread_info.get('name', 'n/a'),
threadId,
code.append("\n# Thread: %s (db:%s) (uid:%s) (url:%s)" %
(thread_info.get('repr', threadId),
thread_info.get('dbname', 'n/a'),
thread_info.get('uid', 'n/a'),
thread_info.get('url', 'n/a')))