Code :
res = Subprocess.Popen(cmd,executable="/bin/bash", shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
while not res.poll():
do something....
I run the python code like: nohup python my_script.py &
And then i want to terminate the sctipt:
kill pid_of_the_script
But it does not work(so the cmd procss created by Subprocess.Popen will be still there) i must use:
kill -9 pid_of_the_script
why the kill command not work here?
As the kill -9 does not kill the cmd process neither, when i capture a SIGTERM signal(this is the problem, as when i send a kill command, the script can not capture this signal, i do register the SIGTERM signal to a signal handler), the handler first kills the cmd process and then use kill -9 to kill the script itself(based on the pid).
updated: maybe the thread.join() method causes this. where call join in the main thread, the main thread seems to can not handler signals...