實現效果如下
原理
利用setproctitle不斷地刷新process name。
實現步驟
import setproctitle
class Config(object):
def __init__(self):
self.process_title = 'V-Net(debug)'
self.epochs = 1000
config = Config()
# 初始化
setproctitle.setproctitle(config.process_title+'({}/{}, %.2fs/it)'.format(str(0), str(config.epochs)) % (0))
# 每一次迭代
epoch = 16 # 爲當前迭代次數,假設爲第16次
setproctitle.setproctitle(config.process_title + '({}/{}, %.2fs/it)'.format(str(epoch + 1), str(config.epochs)) % (end_time-start_time))
拓展
你也可以加入一些其他參數,每一次迭代時都刷新一次,達到實時顯示的效果。