Jupyter notebook 中的 watch 命令

Watch command in Jupyter notebook

我想在 Jupyter 笔记本中执行 watch -n 0.5 nvidia-smi,但它只显示一行。有什么办法可以实现吗?

这是我能够继续打印 GPU 信息的唯一方法。

import time
from IPython.display import clear_output

while True:
  time.sleep(1)
  !nvidia-smi
  clear_output(wait=True)