win10
- 将以下代码保存为.py即可
import time
import subprocess
import locale
import codecs
import os
cmd = "nvidia-smi"
interval = 3
while True:
ps = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
for i in range(0,13):
data = ps.stdout.readline()
# bytes转化为str
data = str(data)
# 判断是否开始于"b'",去掉
if data.startswith('b\''):
data = data[2:]
#同样去掉尾部
if data.endswith('\\r\\n\''):
data = data[:len(data)-5]
print(data)
print("\n\n\n\n\n\n\n")
time.sleep(interval)
linux
- 每隔0.1秒刷新一次
watch -n 0.1 -d nvidia-smi