python脚本失败时记录 [英] Log when python script failed
问题描述
我正在通过服务器上的屏幕会话运行一个相当复杂的python脚本.有时,几个小时后,它崩溃了,我不知道为什么.由于脚本在屏幕上运行,因此当脚本崩溃时,我无法访问该错误.有什么方法可以通过日志记录或简单的管道来提取该信息?
I am running a rather complex python script through a screen session on my server. Sometimes, after some hours, it crashes and I can’t figure out why. Since the script runs in screen, I don’t get access to the error when the scrips crashes. Is there any way to extract that info through logging or a simple pipe?
推荐答案
您可以使用 nohup
和&
在后台运行python命令.默认输出将任何打印输出(包括终止脚本的错误)记录在nohup.out文件中.您可以使用>
You can use nohup
and &
to run your python command in the background. The default output will log any printed outputs (including the error that terminates your script) in a nohup.out file. You can specify the file output in Bash using >
例如
nohup python my_python_script.py > my_output_log &
这篇关于python脚本失败时记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!