简体   繁体   English

如何在/ var / log / messages中调试“检测到的未处理的Python异常”

[英]How to debug 'detected unhandled Python exception in' /var/log/messages

I have a python script checking status of my web service schedules for let's say 2000 times. 我有一个python脚本检查我的Web服务计划的状态,例如说2000次。 One check takes like 5 minutes so the script execution takes like 2000x5 minutes. 一次检查大约需要5分钟,因此脚本执行大约需要2000x5分钟。

I have application logs set up by logger and my system logs just to log information what is going on while script is running. 我有由记录器设置的应用程序日志,而我的系统日志只是为了记录信息,以了解脚本运行时的情况。 However, script stops from some reasons. 但是,脚本由于某些原因而停止。 There is no single entry in my customized logs. 我的自定义日志中没有任何条目。 The only thing I can find is 我唯一能找到的是

less /var/log/messages


 cat /var/log/messages | grep --color "pycharm.py"
Mar 27 08:48:48 hostname python: detected unhandled Python exception in 'pycharm.py'
Mar 30 13:58:16 hostname python: detected unhandled Python exception in 'pycharm.py'
Mar 31 08:22:01 hostname python: detected unhandled Python exception in 'pycharm.py'
Apr  1 05:42:09 hostname python: detected unhandled Python exception in 'pycharm.py'
Apr  2 03:04:16 hostname python: detected unhandled Python exception in 'pycharm.py'

The environment is Red Hat 7.2 环境是Red Hat 7.2

Can anyone suggest to add some lines to script to chatch errors. 任何人都可以建议在脚本中添加一些行来聊天错误。

Things like do not give me anything. 诸如此类的事情不会给我任何东西。

try: 
   command
except:
   smth

You should log the unhandled exception as well as its stack trace, so you know what when wrong and where. 您应该记录未处理的异常及其堆栈跟踪,以便知道什么时候出错以及在哪里。

Use logger.exception() to log the exception content and stack trace. 使用logger.exception()记录异常内容和堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM