当前位置: 代码迷 >> 综合 >> nohup python缓存问题
  详细解决方案

nohup python缓存问题

热度:82   发布时间:2023-12-12 21:28:48.0

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

深度学习用python跑数据时,经常会用到nohup命令,通常的命令格式如下:

nohup python [python source file] (> [log file]) 2>&1 &

如果没有指定输出文件,nohup会将输出放到nohup.out文件中,但在程序运行过程中nohup.out文件中不能实时的看到python的输出,原因是python的输出有缓冲。

解决方案如下:

  • 方案一

使用-u参数,使python输出不进行缓冲,命令格式如下:

nohup python -u [python source file] (> [log file]) 2>&1 &
  • 方案二
export PYTHONUNBUFFERED=1
nohup python [python source file] (> [log file]) 2>&1 &

参考资料

https://stackoverflow.com/questions/12919980/nohup-is-not-writing-log-to-output-file