我如何添加信号处理程序写在Py3k / Python中的壳呢?(How can I add sign

2019-10-17 09:46发布

我正在写一个外壳,但我希望有存根的信号处理程序,当用户点击即控制-C或控制-Z。 我的代码如下: 因为我已经调查过,我可以得到它不是一个控制-Z停止,但仍然暂停在控制-Z。

代码的最新发布版本是在http://JonathansCorner.com/cjsh/download.cgi 。 我工作的代码是:

def handle_signal(signal_number, frame):
    print ('''

CJSH does not support the traditional and rather archaic methods of job
control. This arises partly from implementation concerns and partly for reasons
practical concerns.

In ye olden dayes with the green glow of terminals, it was important to have a
sophisticated job handling in place so jobs could be stopped, suspended, put in
the foreground, and so on and so forth, and for that matter this feature is
still used despite the fact that it was essentially a consolation prize for not
having multiple windows.

Don't try to suspend, resume, background, foreground, etc.

There is a more excellent way.

Now we have not the consolation prize but the real thing: unless you're on a
netbook or smaller, you can open another window for another job. If you have no
more use for a job, close the window.

Just open another window, or maybe a tab.

''')

signal.signal(signal.SIGTSTP, handle_signl)
signal.signal(signal.SIGHUP, handle_signal)
signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGQUIT, handle_signal)
signal.signal(signal.SIGABRT, handle_signal)
signal.signal(signal.SIGALRM, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)

#signal.siginterrupt(signal.SIGTSTP, False)
#signal.siginterrupt(signal.SIGHUP, False)
#signal.siginterrupt(signal.SIGINT, False)
#signal.siginterrupt(signal.SIGQUIT, False)
#signal.siginterrupt(signal.SIGABRT, False)
#signal.siginterrupt(signal.SIGALRM, False)
#signal.siginterrupt(signal.SIGTERM, False)

有什么需要改变这里,我应如何改变它,这样handle_signal()被调用,那么事情继续滴答?

文章来源: How can I add signal handlers to a shell written in Py3k/Python?