Linux笔记-结合nohup执行Python脚本时同步输出结果

版权声明:本文为博主原创文章,转载请注明来源。 https://blog.csdn.net/Dream_angel_Z/article/details/50382240

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

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

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

解决方法:

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

修改命令如下:

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

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

猜你喜欢

转载自blog.csdn.net/Dream_angel_Z/article/details/50382240
今日推荐