Killing threads, and os.system()

Laurent Claessens moky.math at
Tue Jan 31 02:45:53 EST 2012

     Hello all

   I've a program that launches a lot of  threads and each of them 
launches a os.system("my_command").

My program also keeps a list of the launched threads, so I can make 
"for" loops on the threads.

My aim is to kill everything with ctrl-C (KeyboardInterrupt).

Of course I tried to do

except KeyboardInterrupt :
    for task in task_list :
       #task_list is the list of threads to be killed

It does not work.

How can I produce an "emergency" stop of all processes, including the 
externals programs that were called by os.system() ?

My aim is of course to write an ultimate log file containing the status 
of the program when KeyboardInterupt was raised. (if not, the unix 
command "kill" does the job ;) )

Thanks for any help
have a good day

More information about the Python-list mailing list