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
[x] install psutil with pip, make sure its in requirements.txt
[x] import psutil and signal into server.py
[x] follow the above plan for how to store pid's in the process_dict
[x] implement the stop_video_by_type, copypasta the kill_child_processes function
[x] replace all .terminate() calls with stop_video_by_type
right now, we map a video in
process_dict
to the output ofsubprocess.Popen
, see https://github.com/SCE-Development/sce-tv/blob/3a4810abb6f7c4105664415a75c245458894adfe/server.py#L52what should really happen is we store
subprocess.Popen to a variable, then store the variable's
pid` field to the dict, like belowthen we should make a function called
stop_video_by_type
which takes one paramvideo_type
which is theUrlType
enum liketo kill a process by its pid, use this function
game plan
psutil
andsignal
intoserver.py
stop_video_by_type
, copypasta thekill_child_processes
function.terminate()
calls withstop_video_by_type