exception KeyboardInterrupt and os.system command

darren kirby bulliver at badcomputer.org
Sun Nov 27 18:13:41 EST 2005


Hello all.

I have a python script here which is just a wrapper for 2 or more system 
commands. I would estimate the program spends at least 95.5% of 'real' time 
running the system commands.

I want to trap the [crtl-c] key combo and exit (somewhat) gracefully if the 
user decides to abort the program. I am using os.system for the system call, 
and I have wrapped the entire main loop in a try: except KeyboardInterrupt 
statement to try to attain these ends.

As it is though, if the program is currently in the system command, only that 
system command is terminated, and the next loop of my program starts.

Is there a way to make this work? ie: terminate the entire script? Will popen 
do this? I don't really want to use popen because all I need is for the 
system command to run, and check the exit status. Also, popen will pooch the 
output of the system commands (which I want to be printed to the console) 
because the system commands (faad, mpg123, and oggenc) have buffered output 
which won't properly be displayed if I simply print each line of the file 
object returned by popen. 

I don't want to use subprocess because I can't expect my users to have 2.4 
installed...

OS is Linux, if it matters.

If you need to see the code it is here:
http://badcomputer.org/unix/dir2ogg/dir2ogg.bot

Although, this code is the program as it stands, not the code I am testing.

Thanks,
-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051127/5d5c4fe1/attachment.sig>


More information about the Python-list mailing list