概述
您应该看看Python Signal Handlers(特别是signal.CTRLuu事件). 在
这里有一个更完整的答案。。。注意:通过使用这些东西,您可以使您的过程变得相当不可更改。在#!/usr/bin/env python
import signal, os
import time
def handler( signum, frame ):
print "Signal handler caught", signum, "@", time.ctime()
if signum == 2:
raise "Caught Signal 2 - Exiting"
#
# Windows Supported Values
#
#signal.signal( signal.SIGABRT, handler )
#signal.signal( signal.SIGFPE, handler )
#signal.signal( signal.SIGILL, handler )
#signal.signal( signal.SIGINT, handler )
#signal.signal( signal.SIGSEGV, handler )
#signal.signal( signal.SIGTERM, handler )
#
# UNIX Supported Values (YMMV)
#
signal.signal( signal.SIGABRT, handler )
signal.signal( signal.SIGALRM, handler )
signal.signal( signal.SIGBUS, handler )
signal.signal( signal.SIGCHLD, handler )
signal.signal( signal.SIGCLD, handler )
signal.signal( signal.SIGCONT, handler )
signal.signal( signal.SIGFPE, handler )
signal.signal( signal.SIGHUP, handler )
signal.signal( signal.SIGILL, handler )
signal.signal( signal.SIGINT, handler )
signal.signal( signal.SIGIO, handler )
signal.signal( signal.SIGIOT, handler )
#signal.signal( signal.SIGKILL, handler )
signal.signal( signal.SIGPIPE, handler )
signal.signal( signal.SIGPOLL, handler )
signal.signal( signal.SIGPROF, handler )
signal.signal( signal.SIGPWR, handler )
signal.signal( signal.SIGQUIT, handler )
signal.signal( signal.SIGRTMAX, handler )
signal.signal( signal.SIGRTMIN, handler )
signal.signal( signal.SIGSEGV, handler )
#signal.signal( signal.SIGSTOP, handler )
signal.signal( signal.SIGSYS, handler )
signal.signal( signal.SIGTERM, handler )
signal.signal( signal.SIGTRAP, handler )
signal.signal( signal.SIGTSTP, handler )
signal.signal( signal.SIGTTIN, handler )
signal.signal( signal.SIGTTOU, handler )
signal.signal( signal.SIGURG, handler )
signal.signal( signal.SIGUSR1, handler )
signal.signal( signal.SIGUSR2, handler )
signal.signal( signal.SIGVTALRM, handler )
signal.signal( signal.SIGWINCH, handler )
signal.signal( signal.SIGXCPU, handler )
signal.signal( signal.SIGXFSZ, handler )
#signal.signal( signal.SIG_DFL, handler )
signal.signal( signal.SIG_IGN, handler )
print time.ctime(), " - Started"
while True:
time.sleep( 1 )
print " Tick:", time.ctime()
最后
以上就是多情小鸭子为你收集整理的python怎么强制退出程序什么键_如何防止Python脚本强制退出?的全部内容,希望文章能够帮你解决python怎么强制退出程序什么键_如何防止Python脚本强制退出?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复