script stuck after show()

The script I am writing gets sometimes stuck after show(). Of course show() halts the script but when I close the window I want it to continue. Is there a sure way to kill off the pylab thread and continue like with a key press event on ESC and then calling a stop routine of the thread.
Thanks in advance
    Wolfgang