Nohup运行Python脚本时,为何print日志输出不及时显示?
- 内容介绍
- 文章标签
- 相关推荐
本文共计216个文字,预计阅读时间需要1分钟。
`nohup` 命令无法及时打印 `python print` 日志。通常,我们会使用 `nohup` 在后台挂起程序,例如:`nohup python main.py > nohup.out` 或 `nohup python main.py >> ans.log 2>&1`。然而,有一天我竟然遇到了问题。
nohup不能及时打印python print日志
nohup python main.py & 默认输出为nohup.out文件
或者定义输出文件为ans.log
nohup python main.py >ans.log 2>&1 &
nohup python -u main.py >ans.log 2>&1 &
即可让程序直接将输出放到ans.log中。
作为日志输出中间的值,就不会遇到上述问题
参考链接
本文共计216个文字,预计阅读时间需要1分钟。
`nohup` 命令无法及时打印 `python print` 日志。通常,我们会使用 `nohup` 在后台挂起程序,例如:`nohup python main.py > nohup.out` 或 `nohup python main.py >> ans.log 2>&1`。然而,有一天我竟然遇到了问题。
nohup不能及时打印python print日志
nohup python main.py & 默认输出为nohup.out文件
或者定义输出文件为ans.log
nohup python main.py >ans.log 2>&1 &
nohup python -u main.py >ans.log 2>&1 &
即可让程序直接将输出放到ans.log中。
作为日志输出中间的值,就不会遇到上述问题
参考链接

