killing a script

MRAB python at mrabarnett.plus.com
Sun Aug 28 21:52:22 EDT 2011


On 29/08/2011 02:15, Russ P. wrote:
> I have a Python (2.6.x) script on Linux that loops through many
> directories and does processing for each. That processing includes
> several "os.system" calls for each directory (some to other Python
> scripts, others to bash scripts).
>
> Occasionally something goes wrong, and the top-level script just keeps
> running with a stack dump for each case. When I see that, I want to
> just kill the whole thing and fix the bug. However, when I hit Control-
> C, it apparently just just kills whichever script happens to be
> running at that instant, and the top level script just moves to the
> next line and keeps running. If I hit Control-C repeatedly, I
> eventually get "lucky" and kill the top-level script. Is there a
> simple way to ensure that the first Control-C will kill the whole darn
> thing, i.e, the top-level script? Thanks.
>
You could look at the return value of os.system, which may tell you the
exit status of the process.



More information about the Python-list mailing list