使用 python 推送异常和错误推送通知



我正在用不同的电子设备进行实验。我有我的脚本(从"MyScript"开始命名,Python3.7和W10(用于远程收集数据。关键是它需要几个小时,有时它会发生异常错误,系统错误或键盘中断,脚本明显停止。

我的想法是,如果发生任何错误和异常,将推送通知用于我的手机,这样我就可以重新启动脚本而不会浪费时间。但是我不知道如何编码...我想应该是这样的:

SendPushNotification():
"This function sends the notification"
if "any Exception, Error or TimeOut occurs":
#MyScript
SendPushNotification():

非常感谢您,我将感谢您的想法!

我使用以下方法解决了它:

try:
MainScript()
except (RuntimeError, TypeError, NameError):
PushNotification("An ERROR has occured!!!")
DoSomething1()
DoAnotherThing()

最新更新