我正在将python与subprocess.Popen()配合使用,以输入实时广播流URL来启动FFmpeg,并每30秒制作一次wav文件。 当我尝试使用subprocess.kill()杀死进程时,它可以工作,但是该进程仍写在/ proc /中,并且如果我签入系统监视器,进程的状态为“ Zombi”。
直到python脚本完成,所以该过程已从/ proc中删除,并且在系统监视器中看不到它。
如何在不关闭python脚本的情况下终止进程?
这是示例
#! /usr/bin/python3
import os
import subprocess
import time
# Start ffmpeg in background.
folder_name = "path_to_file"
input_ = "https://kanlivep2event-i.akamaihd.net/hls/live/749629/749629/kanmoreshet_mp3/chunklist.m3u8"
ffmpeg_cmd = [
"ffmpeg",
"-y",
"-loglevel", "8",
"-thread_queue_size", "1500",
"-i", input_,
"-c", "copy",
"-vn",
"-f", "segment",
"-segment_time", "30",
"-ar", "8000",
"-acodec", "pcm_s32le",
"-ac", "1",
"-strftime", "1",
str(folder_name + '/' + input_.replace("/","") + '_*_*_%s.wav')
]
process = subprocess.Popen(ffmpeg_cmd)
# Check if the process is exist
def check_exist(process):
print("pid - ", process.pid)
if os.path.isdir("/proc/{}".format(process.pid)):
print ("Yes")
else:
print("No")
check_exist(process)
process.kill()
time.sleep(20)
check_exist(process)