killing a script

Russ P. russ.paielli at gmail.com
Sun Aug 28 23:22:10 EDT 2011


On Aug 28, 8:16 pm, Chris Rebert <c... at rebertia.com> wrote:
> On Sun, Aug 28, 2011 at 8:08 PM, Russ P. <russ.paie... at gmail.com> wrote:
> > On Aug 28, 7:51 pm, Chris Angelico <ros... at gmail.com> wrote:
> >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. <russ.paie... at gmail.com> wrote:
> >> > On Aug 28, 6:52 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> >> >> You could look at the return value of os.system, which may tell you the
> >> >> exit status of the process.
>
> >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems
> >> > that there should be a simpler way to just kill the "whole enchilada."
> >> > Hitting Control-C over and over is a bit like whacking moles.
>
> >> I believe the idea of this suggestion is for the outer script to
> >> notice that the inner script terminated via Ctrl-C, and would then
> >> immediately choose to terminate itself - thus avoiding the
> >> whack-a-mole effect.
>
> >> ChrisA
>
> > Yes, but if I am not mistaken, that will require me to put a line or
> > two after each os.system call.
>
> Er, just write a wrapper for os.system(), e.g.:
>
> def mysystem(cmd):
>     if os.system(cmd):
>         sys.exit()
>
> Also, you may want to switch to using the `subprocess` module instead.
>
> Cheers,
> Chris

Sounds like a good idea. I'll give it a try. Thanks.

--Russ P.



More information about the Python-list mailing list