如何防止用户通过CTRL + Z停止脚本?

sha*_*pan 2 python signals background command-line-interface

我想通过在我的python命令行解释器脚本中按CTRL+ 来阻止用户返回shell_prompt Z.

Zel*_*luX 9

您可以为SIGTSTP编写一个信号处理程序,它由Ctrl+ 触发Z.这是一个例子:

import signal

def handler(signum, frame):
    print 'Ctrl+Z pressed, but ignored'

signal.signal(signal.SIGTSTP, handler)

while True:
   pass 
Run Code Online (Sandbox Code Playgroud)