Py3k Signal Handling

Jonathan Hayward jonathan.hayward at pobox.com
Sat Nov 10 17:08:36 CET 2012


I am working on writing a shell, but I want to have stubbed signal handlers
when the user hits i.e. control-C or control-Z. My code is as follows; as I
have investigated it, I can get it to not stop on a control-Z, but still
suspend on a control-Z.

The most recent published version of the code is at
http://JonathansCorner.com/cjsh/download.cgi<http://jonathanscorner.com/cjsh/download.cgi>.
The code I am working on is:

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)

What needs changing here and how should I change it so that handle_signal()
is called and then things keep on ticking?

As posted to
http://stackoverflow.com/questions/13318447/how-can-i-add-signal-handlers-to-a-shell-written-in-py3k-pythonwith
only one response about the signal that is converted to a
KeyboardInterrupt exception.

-- 
[image: Christos Jonathan Hayward] <http://jonathanscorner.com/>
Jonathan Hayward, an Orthodox Christian author.

*Amazon <http://amazon.com/author/cjshayward>* • Author
Bio<http://jonathanscorner.com/author/>
 • *Email <christos.jonathan.hayward at gmail.com>* •
Facebook<http://www.facebook.com/christos.jonathan.hayward>
 • Google Plus <http://jonathanscorner.com/plus> •
LinkedIn<http://www.linkedin.com/in/jonathanhayward>
 • Twitter <http://twitter.com/JonathansCorner> •
*Web<http://jonathanscorner.com/>
* • What's New? <http://jonathanscorner.com/>
If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner <http://www.amazon.com/dp/1478219912>*.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121110/9ee770e2/attachment-0001.html>


More information about the Python-list mailing list