banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

nohup 后台运行python程序print无输出

使用 nohup 后台运行 python,print 没有输出到日志

nohup python foobar.py > foobar.log 2>&1 &

发现 foobar.log 中显示不出来 python 程序中 print 的东西。 这是因为 python 的输出有缓冲,导致 foobar.log 并不能够马上看到输出。 python 有个 - u 参数,使得 python 不启用缓冲。

nohup python -u foobar.py > foobar.log 2>&1 &

其他玩法:只输出错误到日志 # Only error write to log nohup python -u ./foobar.py> /dev/null 2>foobar.log & 不输出到日志 # Nothing to Display nohup python -u ./foobar.py> /dev/null 2>&1 & 全部 print 输出到日志 # Write all to log nohup python -u ./foobar.py> ./foobar.log 2>&1 &

https://blog.csdn.net/Statham\_stone/article/details/78290813

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.