[Tutor] keyboard interrupt

eryksun eryksun at gmail.com
Thu May 23 00:05:49 CEST 2013


On Wed, May 22, 2013 at 4:30 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
>
> Figured it out. Ctrl-C only works in the Windows Command window, not
> in an editor.

Which IDE?

In IDLE, your code runs in the main thread of a subprocess (unless
IDLE is started with the -n option). A second thread ("SockThread") is
started to communicate with PyShell over a socket. When you press
ctrl-c, PyShell executes an interprocess call to
interrupt_the_server(), which simply executes thread.interrupt_main()
-- i.e. interrupt the main thread with a KeyboardInterrupt:

    >>> import thread
    >>> thread.interrupt_main()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyboardInterrupt

Almost certainly your IDE supports interrupting the execution of code.
You just need to configure the key binding. The default binding for
ctrl-c on Windows is to copy the selection to the clipboard.


More information about the Tutor mailing list