Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > exception KeyboardInterrupt and os.system command

Reply
Thread Tools

exception KeyboardInterrupt and os.system command

 
 
darren kirby
Guest
Posts: n/a
 
      11-27-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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBDij2swPD5Cr/3CJgRAnFMAKCUBJEsuuUI2kwYWmdXmEF4diDEjgCgwCsm
hcaFHgOzSSWmKGCqPni0X/Y=
=qMkk
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      11-27-2005
darren kirby wrote:
> 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.



From "man system":

"""
The system() function hands the argument string to the command inter-
preter sh(1). The calling process waits for the shell to finish
execut-
ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.
"""

So - I guess its popen2 or nothing

Regards,

Diez
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching a non-Exception object (KeyboardInterrupt) Michael Goerz Python 3 02-04-2008 02:34 PM
Trace KeyboardInterrupt exception? Tony Nelson Python 4 06-15-2006 07:34 PM
Re: exception KeyboardInterrupt and os.system command darren kirby Python 1 11-29-2005 08:26 AM
Re: exception KeyboardInterrupt and os.system command jepler@unpythonic.net Python 3 11-28-2005 06:21 PM
Socket object and KeyboardInterrupt exception PantherSE Python 0 05-16-2005 09:10 PM



Advertisments