I am using this code
p1 = Popen(['rtmpdump'] + cmd_args.split(' '), stdout=PIPE)
p2 = Popen(player_cmd.split(' '), stdin=p1.stdout, stderr=PIPE)
p2.wait()
# try to kill rtmpdump
# FIXME: why is this not working ?
try:
p2.stdin.close()
p1.stdout.close()
p1.kill()
except AttributeError:
# if we use python 2.5
from signal import SIGTERM, SIGKILL
from os import kill
kill(p1.pid, SIGKILL)
when p1 terminates then p2 is terminated too. the problem is:
If I manually close p2 (it's mplayer), rtmpdump/p1 is still running. I tried various things like what is above but I still can't kill it. i tried with adding close_fds=True.
so may be rtmpdump still tries to write to stdout. but why is this cause kill() to fail ?
full source code: http://github.com/solsticedhiver/arte-7.py
Edit: Here is the fix. call wait() after kill() to really kill the zombie process
# kill the zombie rtmpdump
try:
p1.kill()
p1.wait()
except AttributeError:
# if we use python 2.5
from signal import SIGKILL
from os import kill, waitpid
kill(p1.pid, SIGKILL)
waitpid(p1.pid, 0)