evilliu

在Linux中,可以使用nohup将脚本放置后台运行,如下:

nohup python myscript.py params1 > nohup.out 2>&1 & 
  • 1

但直接使用上面代码,无法在程序运行过程中查看Python中的print "computing" 输出结果,比如在每次循环中使用print语句等。原因是python的输出有缓冲,导致nohup.out不能够马上看到输出。

解决方法:

  • 使用-u参数,使得python不启用缓冲。

修改命令如下:

nohup python -u myscript.py params1 > nohup.out 2>&1 & 
  • 1
  • 2

这样就可以同步看到输出结果了。

分类:

技术点:

相关文章:

  • 2021-12-16
  • 2021-10-18
  • 2022-02-07
  • 2021-12-24
  • 2022-12-23
  • 2021-12-24
  • 2021-12-24
  • 2021-12-16
猜你喜欢
  • 2021-12-06
  • 2021-12-06
  • 2022-01-03
相关资源
相似解决方案