python脚本失败时记录 [英] Log when python script failed

查看:76
本文介绍了python脚本失败时记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过服务器上的屏幕会话运行一个相当复杂的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屋!

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