def show_threads():
"""
Log the name, ident and daemon flag of all alive threads in DEBUG level
"""
if logger.isEnabledFor(logging.DEBUG):
all_threads = threading.enumerate()
max_name = reduce(max, map(len, [t.name for t in all_threads]))
max_ident = reduce(max, map(int, map(math.ceil, map(math.log10, [t.ident for t in all_threads if t.ident is not None]))))
msg = ['Name' + ' '*(max_name-2) + 'Ident' + ' '*(max_ident-3) + 'Daemon',
'='*max_name + ' ' + '=' * max_ident + ' ======']
fmt = '%{0}.{0}s %{1}d %d'.format(max_name, max_ident)
for t in threading.enumerate():
msg.append(fmt % (t.name, t.ident, t.daemon))
logger.debug("Threads currently alive on process %d:\n%s", os.getpid(), '\n'.join(msg))
评论列表
文章目录