install Ctrl-C handler

James Henderson james at logicalprogression.net
Wed Feb 4 07:15:31 EST 2004


On Wednesday 04 February 2004 12:04 pm, Uwe Mayer wrote:
> Hi,
>
> can anybody tell me how you install something like a Ctrl-C handler in
> Python, i.e. a routine that is called when ^C is pressed and that can do
> cleanup work?
>
> Thanks
> Uwe

Maybe you require something more sophisticated but ctrl-C raises an exception 
that can be caught:

>>> try:
...     while 1: pass
... except KeyboardInterrupt:
...     print 'Interrupted!'
...
Interrupted!


James
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/





More information about the Python-list mailing list