This is not a bug.  Maintainer, please close this bug #411416.

> #!/usr/bin/python
>
> import subprocess
> import os
> import signal
> import time
>
> PATH_MPLAYER='/usr/bin/mplayer'
> cmdList = [PATH_MPLAYER, '/home/woodmood/tmp/delme.wav']
> # proc = subprocess.Popen (cmdList)
> pid = os.spawnv (os.P_NOWAIT, PATH_MPLAYER, cmdList)
> time.sleep (5)
> # os.kill (proc.pid, signal.SIGTERM)
> os.kill (pid, signal.SIGKILL)
> os.wait()
>
> What happens when run from Konsole is that mplayer dies, *without*
> writing anything to the terminal and the script terminates and command
> prompt reappers.
> However, if I press any keys, nothing appears on the screen
> (confiriming by enter executes a command though). This is most

That's because you terminated mplayer with SIGKILL and mplayer did
not have a chance to reset the terminal modes to a usable state.

This behavior is correct and can be easily explained.  When you kill the
mplayer process with SIGKILL, mplayer by definition of SIGKILL, cannot
write anything to the terminal (or perform any other cleanup for that
matter).
>From the Linux "signal(7)" man page:
    The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.


> probably an error in python because when I try running mplayer
> manually and then sending it signal using:
>
> $ kill -SIGKILL mplayer's_pid
>
> mplayer dies stating 'Killed' and terminal stays alive as it should.

Mplayer did NOT print 'Killed' on the terminal.  The 'Killed' text you
see on your screen is printed by the shell, which performed the
Linux "wait" system call, analogous to the "os.wait()" in your
python script.  The shell, which is waiting for mplayer, resets
the terminal modes, turning on key echo (similar to the reset(1)
command).

When you use Python's "os.spawnv", there is no shell waiting for your
instance of mplayer to terminate.  From python help(os):
    [...] arguments will be passed directly to
        the program without shell intervention (as with os.spawnv())
    [...]
    spawnv(mode, file, args)
        spawnv(mode, file, args) -> integer
        Execute file with arguments from args in a subprocess.
        If mode == P_NOWAIT return the pid of the process.
        If mode == P_WAIT return the process's exit code if it exits
normally;
        otherwise return -SIG, where SIG is the signal that killed it.

In the case of your script, it would be your script's responsibility
(NOT Python's) to ensure that the terminal modes are reset
(see command 'reset(1)' man page and the Python 'curses'
module).  Your script would examine the return value from
os.wait() and if the process was killed by an unblockable signal,
such as SIGKILL, then your script would reset the terminal to
default modes with echo turned on via the Python curses
module.  BUT -- Please do NOT use SIGKILL!

If you modify your script to send SIGTERM instead of SIGKILL,
you will see Mplayer print this:

    MPlayer interrupted by signal 15 in module: play_audio

By the way, this is one reason you should not routinely use
SIGKILL.  SIGKILL should only be used when a process is
hung and cannot be killed any other way.  If you use a
SIGTERM or SIGINT in the python script, you will see that
mplayer WILL leave the terminal in a USABLE state.  If you
routinely use SIGKILL programs do not have a chance to
clean up anything and can adversely affect your whole
system in some situations.

SIGTERM is the default signal sent by the kill shell command.
SIGINT is the signal sent from a terminal interrupt (control-C).

-Rob



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to