[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Process in not get killed using subprocess.call() in python thread

I have created one thread in python, and that thread is running in infinite loop, but when I was trying to kill a process by making use of subprocess.call("my ps command") Its not actually working

Here is the code,

import threading
import subprocess

def B():
    while True:
        cmd="ps -ef | grep 'shell.py --server' | awk '{print $2}' | xargs kill -9"
        subprocess.call(cmd, shell=True)

def A():
    th = threading.Thread(target=B)

In above example, subprocess.call() getting executed but not actually killing the process that I want. If I executed command manually then its working fine, but in thread its not.