Terminating python script easily

Bahadir Balban bilgehan.balban at gmail.com
Thu Oct 22 09:03:51 EDT 2009


On Thu, Oct 22, 2009 at 4:01 PM, Jean-Michel Pichavant
<jeanmichel at sequans.com> wrote:
> Balban 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
>>
>
> you may want to use subprocess instead of os.system.
> On catching CTRL+C, you kill all the pid started with subprocess and exit
> the script smoothly.
>
> JM
>

Hmm. OK, this is what I suspected I needed. So no explicit signal
catching is required I guess.

I will look into it, thanks.


Bahadir



More information about the Python-list mailing list