nohup和python没有错误消息? [英] no error messages with nohup and python?

查看:139
本文介绍了nohup和python没有错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有nohup的linux服务器上运行python脚本,

I run a python script on a linux server with nohup like that:

nohup python3 ./myscript.py > ./mylog.log &

它可以工作并且脚本会写日志文件,但是问题是python错误消息/抛出异常似乎没有写入日志文件。我怎么能做到这一点?

It works and the script writes the log file but the problem is that python error messages / thrown exceptions don't seem to get written into the log file. How could I achieve this?

这与stderr有关吗? (但是在我启动脚本时,它说: nohup:将stderr重定向到stdout。)

Has this something to do with stderr? (but it says: "nohup: redirecting stderr to stdout" when I start the script.)

这是一个运行时间较长的脚本,一段时间后有时该脚本会停止工作由于某些问题并且缺少错误消息,我不知道为什么。问题总是在几天后发生,因此调试起来确实很痛苦。

It is a long running script and after a while sometimes the script stops working because of some problem and with missing error messages I have no clue why. The problems always happen after a few days so this is really a pain to debug.

编辑:
可能与冲洗有关吗?由于我自己的打印使用冲洗功能,但是python错误可能不会出现,因此一旦脚本中止,它们就不会显示在文件中?

edit: Could it have something to do with flush? Since my own prints use flush but maybe python errors don't so they don't show up in the file once the script aborts?

推荐答案

我找到了原因。确实是缓冲问题(请参见上面的编辑)。 :)

I have found the reason. It really was the buffering problem (see my edit above). :)

nohup python3 -u ./myscript.py > ./mylog.log &

使用python -u参数可以正常工作。

With the python -u parameter it works. It disables buffering.

现在我可以去找虫子了……

Now I can go bug hunting...

这篇关于nohup和python没有错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆