Catching control-C
Piet van Oostrum
piet at cs.uu.nl
Mon Jul 6 19:05:44 EDT 2009
>>>>> Philip Semanchuk <philip at semanchuk.com> (PS) wrote:
>PS> 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.
>PS> You can use a try/except to catch a KeyboardInterrupt exception, or you
>PS> can trap it using the signal module:
>PS> http://docs.python.org/library/signal.html
>PS> You want to trap SIGINT.
And make sure threads don't mess up the signal handling.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list