def show_kernels():
"""Show all IPython Kernels on System"""
total_mem = psutil.virtual_memory().total
html = ('<h3>IPython Notebook Processes on {}</h3>'
'<table><tr>'
'<th>Username</th><th>PID</th><th>CPU Usage</th>'
'<th>Process Memory</th><th>System Memory Used</th><th>Status</th>'
'</tr>').format(platform.node())
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'username', 'cmdline',
'memory_info', 'status'])
except psutil.NoSuchProcess:
pass
else:
if any(x in pinfo['cmdline'] for x in ['IPython.kernel',
'ipykernel_launcher']):
html += '<tr>'
html += '<td>{username}</td><td>{pid}</td>'.format(**pinfo)
p = psutil.Process(pinfo['pid']).cpu_percent(0.1)
html += '<td>{}%</td>'.format(p)
html += '<td>{:.4} Mb</td>'.format(pinfo['memory_info'].vms /
1024**3)
html += '<td>{:.3}%</td>'.format(100 *pinfo['memory_info'].vms /
total_mem)
html += '<td>{}</td>'.format(pinfo['status'])
html += '</tr>'
html += '</table>'
return HTML(html)
评论列表
文章目录