[Idle-dev] Interruptable code?

Kurt B. Kaiser kbk at shore.net
Sat Dec 16 09:21:20 CET 2006

"Douglas S. Blank" <dblank at brynmawr.edu> writes:

> I notice that in IDLE when running with -n (no processes) that:
>>>> while 1: 1
> can be stopped with control+c, but:
>>>> while 1: None
> cannot. I realize that this is true because the second example doesn't
> cause anything to be written in the IDLE window, and the first does.

Yes. The cancel state is checked when PyShell.write() is called.

> I see that running without the additional subprocess might make this a
>hard bug to fix. But, is there something I can call like so:
>>>> while 1: func()
> where:
> def func():
>    # a call to check for control+c or update IDLE
>    return None

def func():
    while True:
          if flist.pyshell.canceled:

while True: func()

(works w/o subprocess)

> Some additional data:
> - I can't use idle with sub processes (because I want to interact with
> Tkinter in a single thread)

If you run with the subprocess and construct Tkinter objects, they run in
a process separate from the IDLE GUI.  This is an advantage in most cases!

One of the objectives for implementing the subprocess was to separate
the IDLE GUI from the user code.  The user code can be interrupted even

while True: pass

(But IDLE Windows has problems with killing user code which is blocked.)


More information about the IDLE-dev mailing list