0

我正在使用此代码

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)

p1终止时p2也终止。

问题是:

如果我手动关闭 p2(它是 mplayer),rtmpdump/p1 仍在运行。我尝试了各种类似上面的东西,但我仍然无法杀死它。我尝试添加close_fds=True.

所以可能 rtmpdump 仍然尝试写入标准输出。但是为什么这会导致 kill() 失败?

完整源代码:http: //github.com/solsticedhiver/arte-7.py

4

1 回答 1

0

这是修复。调用wait()kill()真正杀死僵尸进程

# 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)
于 2013-04-08T19:45:04.840 回答