简体   繁体   English

如何设置我的python程序错误终止时将要执行的操作?

[英]How can I set what will be done when my python program terminates with error?

Is there any method to set certain action when my python program ends abruptly? 当我的python程序突然结束时,有什么方法可以设置某些操作? Especially I want to delete a folder and leave a log what was the error using logging module. 特别是我想删除一个文件夹并留下日志,这是使用日志记录模块的错误。

根据您“突然结束”的含义,可能正在寻找atexit模块https://docs.python.org/2/library/atexit.html

您可以使用错误处理,尤其是使用Try,Except语句。

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

相关问题 python程序终止后,如何保持控制台窗口打开以查看产生的任何错误? - How do I keep a console window open after my python program terminates to see any errors produced? 如何正确完成我的自卸车程序? - How can I get my Tipper program done right? 为什么我将数据写入 csv 时会收到 KeyError? 可以做些什么来创建异常错误处理? - Why do I receive a KeyError when I write my data to csv? What can be done to create exception error handling? python:一旦完成我想要的操作,我如何使我的函数停止读取列表 - python: how can i make my function stop reading through a list once its done what i want 我如何设置我的程序运行直到出现错误,以便如果出现错误,它会再试一次? - How can i set my program to run until get an error and so that if it gets an error it will try again? Python:程序意外终止 - Python: Program unexpectedly terminates 我的问题可以在 Python 中解决吗? 是这样,怎么样? - Can my problem be done in Python? Is so, How? 如何找出在python程序中创建这么多线程的原因? - How can I find out what's creating so many threads in my python program? 如何理解运行此Python程序时遇到的错误? - How do I understand what error I am getting when running this Python program? 打开我的程序时,如何使 function 工作? Python - How can I make a function work when I open my program? Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM