如何在python中处理os.system sigkill信号? [英] how to handle os.system sigkill signal inside python?

查看:193
本文介绍了如何在python中处理os.system sigkill信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,在其中我从操作系统中调用了一个漫长的过程.过了一会儿,我调用的进程被SIGKILL信号终止了.

I have a python script where I call a lengthy process from the operating system. After a long while, the process that I call gets terminated by the system by SIGKILL signal.

是否可以像尝试并捕获情况那样从Python内部处理此问题?

Is it possible to handle this from inside Python like in a try and catch situation?

我应该使用哪种方法来解决此问题.非常重要的一点是,此过程应保持尽可能长的运行时间,而不会受到任何干扰.

What method should I use to solve this issue. It is very important that this process keeps on running as long as possible without any interruptions.

推荐答案

无法处理SIGKILL

不能捕获,阻止或忽略信号SIGKILL和SIGSTOP.

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

如果您希望妥善处理系统关闭,则应该处理SIGTERM或启动/关闭脚本,例如启动工作初始化. d脚本.

If you're looking to handle system shutdown gracefully, you should be handling SIGTERM or a startup/shutdown script such as an upstart job or a init.d script.

这篇关于如何在python中处理os.system sigkill信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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