Abort script that renders frames My script runs through a for loop, each time rendering a frame. How can I abort the script?

Normally, I'd use CTL+C in the terminal Blender was launched from, but this doesn't work.  It just waits until the current frame is done and then raises a KeyboardInterrupt exception in some file called .../2.69/scripts/addons/cycles/engine.py, but continues on to the next frame.

Here is a simplified version of my script:

import bpy

framesToRender = (1, 3, 4, 6, 7)

for frame in framesToRender:
    bpy.context.scene.frame_set(frame)
    bpy.context.scene.render.filepath = "/home/garrett/Desktop/" + str(frame).zfill(4)
    bpy.ops.render.render(write_still=True)    



EDIT:

The only way I've figured out to stop it is by killing Blender from the System Monitor (for Ubuntu), or close the terminal Blender was launched from. Using xkill on Blender kills the user interface, but doesn't stop the script.
To stop the loop you can install your own handler for the SIGINT signal which is executed by the main thread. (see signal module)

The rendering of the current frame will not abort.

import bpy
import signal

abort = None

def hndl(signum, frame):
    global abort
    abort = True
    print("\nAbort")
    #uncomment to call the default handler
    #raising the KeyboardInterruption exception
    #signal.default_int_handler(signum, frame)

def run():
    global abort
    signal.signal(signal.SIGINT, hndl)
    count = 0
    abort = False
    while not abort and count &lt; 10:
        count += 1
        print(count, abort)
        bpy.ops.render.render()

def reset():   
    signal.signal(
        signal.SIGINT, 
        signal.default_int_handler
        )

if __name__== "__main__":
    run()
    reset()