nohup python 日志不能输出的问题

在执行 nohup python my_script.py & 时,生成的 nohup.out 文件为空。

原因是:stdout 没有及时 flush

解决办法:添加python启动参数-u

参数说明:

# python --help
...
-u     : force the binary I/O layers of stdout and stderr to be unbuffered;
         stdin is always buffered; text I/O layer will be line-buffered;
         also PYTHONUNBUFFERED=x
...

参考链接:
https://stackoverflow.com/questions/25674613/python-nohup-out-dont-show-print-statement