Terminating python script easily

Benjamin Kaplan benjamin.kaplan at case.edu
Thu Oct 22 08:59:53 EDT 2009


On Thu, Oct 22, 2009 at 8:46 AM, Balban <bilgehan.balban at gmail.com> wrote:
> Hi,
>
> I have a python build script that calls various commands, some using
> os.system().
>
> Often, if I want to terminate the script prematurely, I press ctrl-c,
> but I have to do this many times before I can kill the script for
> good. I was wondering is there a way that I define a signal handler
> and kill the whole thing at once with a single ctrl-c? Perhaps I
> should  also call my other scripts with a method other than os.system
> () as well?
>
> Thank you,
>
> Bahadir
> --
In Python, ctrl-C raises a KeyboarInterrupt. You can just catch that
and terminate everything in the except clause. If you're using 2.6,
subprocess.Popen has a terminate method you can use to quit the other
scripts if you use that instead of os.system.



More information about the Python-list mailing list