SCE-Development / sce-tv

SCE TV
2 stars 1 forks source link

Keep track of process IDs in process_dict #19

Closed evanugarte closed 8 months ago

evanugarte commented 9 months ago

right now, we map a video in process_dict to the output of subprocess.Popen, see https://github.com/SCE-Development/sce-tv/blob/3a4810abb6f7c4105664415a75c245458894adfe/server.py#L52

what should really happen is we store subprocess.Popen to a variable, then store the variable'spid` field to the dict, like below

process = subprocess.Popen(
    command, 
    stdout=subprocess.DEVNULL, 
    stdin=subprocess.DEVNULL, 
    stderr=subprocess.DEVNULL
)

process_dict[rtmp_stream_url][video_type] = process.pid

then we should make a function called stop_video_by_type which takes one param video_type which is the UrlType enum like

def stop_video_by_type(video_type: UrlType):
  # check if video_type is in dict
  # if so, then kill the process by its id, pop the element from the dict
  pass

to kill a process by its pid, use this function

def kill_child_processes(parent_pid, sig=signal.SIGKILL):
    try:
        parent = psutil.Process(parent_pid)
    except psutil.NoSuchProcess:
        return
    children = parent.children(recursive=True)
    for process in children:
        process.send_signal(sig)

game plan