使用nohup运行Python脚本,为何print语句无输出显示?
- 内容介绍
- 文章标签
- 相关推荐
本文共计136个文字,预计阅读时间需要1分钟。
bashnohup python test.py > nohup.out 2>&1 &查看nohup.out文件,发现没有显示Python程序中print的输出。这是由于Python的输出有缓冲,导致nohup.out中看不到输出。可以通过添加-u参数给python,使其不使用缓冲,命令如下:nohup python -u test.py > nohup.out 2>&1 &
nohup python test.py > nohup.out 2>&1 &
发现nohup.out中显示不出来python程序中print的东西。
这是因为python的输出有缓冲,导致nohup.out并不能够马上看到输出。
python 有个-u参数,使得python不启用缓冲。
nohup python -u test.py > nohup.out 2>&1 &
本文共计136个文字,预计阅读时间需要1分钟。
bashnohup python test.py > nohup.out 2>&1 &查看nohup.out文件,发现没有显示Python程序中print的输出。这是由于Python的输出有缓冲,导致nohup.out中看不到输出。可以通过添加-u参数给python,使其不使用缓冲,命令如下:nohup python -u test.py > nohup.out 2>&1 &
nohup python test.py > nohup.out 2>&1 &
发现nohup.out中显示不出来python程序中print的东西。
这是因为python的输出有缓冲,导致nohup.out并不能够马上看到输出。
python 有个-u参数,使得python不启用缓冲。
nohup python -u test.py > nohup.out 2>&1 &

