Catching control-C

Philip Semanchuk philip at semanchuk.com
Mon Jul 6 17:47:57 EDT 2009


On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote:

> What is required in a python program to make sure it catches a  
> control-
> c on the command-line? Do some i/o? The OS here is Linux.

You can use a try/except to catch a KeyboardInterrupt exception, or  
you can trap it using the signal module:
http://docs.python.org/library/signal.html

You want to trap SIGINT.


HTH
Philip



More information about the Python-list mailing list