I've been trying to figure out how to spin up different subprocess instances and then killing them and then creating new ones. The parent python process never does, it just kills the subprocesses. I followed a lot of links on SO but I keep getting the following message once the parent python process ends:
F/Users/Lucifer/miniconda3/envs/rltp/lib/python3.6/subprocess.py:761: ResourceWarning: subprocess 40909 is still running ResourceWarning, source=self)
it seems interesting because I did ps
but I get nothing:
PID TTY TIME CMD
7070 ttys001 0:00.06 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -fp Lucifer
7072 ttys001 0:00.61 -bash
17723 ttys002 0:00.06 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -fp Lucifer
17725 ttys002 0:00.06 -bash
38586 ttys002 0:00.16 sertop --no_init
I simply want to start a process:
self.serapi = subprocess.Popen(['sertop','--no_init'],
stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,
preexec_fn=os.setsid,shell=True
,)
and kill it:
os.killpg(os.getpgid(self.serapi.pid), signal.SIGTERM)
the above code is essentially copied from the top answer:
How to terminate a python subprocess launched with shell=True
but I am unsure why I get this message. Am I killing the child process successfully? I plan to start and kill many of them.
Note I don't know or need shell=True
. I just copied that cuz thats how the answer/question I posted has it. I'd prefer to not have that parameter.
according to the answer I tried:
def kill(self):
self.serapi.wait()
#self.serapi.kill()
self.serapi.terminate()
#os.killpg(os.getpgid(self.serapi.pid), signal.SIGTERM)
#self.serapi.wait()
and different permutations of the above but nothing really seemed to work. Any advice?