I am keyboard manager script that listens for keys and starts process in the background. This is done mainly for the sake of convenience. Let's say I press the hotkey that lunches the application below. The application lunches as a child process of the parent (the keyboard manager script). Sometimes, I get a problem with the process and I need to kill it so that I can run a new one. However, if I kill the child process, it doesn't go away and remains a zombie process of the parent. I would like to know how to kill the child process and have it go away (i.e., stop being a zombie process).
if "jupyter-lab" not in (p.name() for p in psutil.process_iter()):
cmd = [ JUPYTER_PATH, "lab", "--notebook-dir=" + NOTEBOOK_PATH]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
start_new_session=True,
)