On 13/07/17 16:42, sanky8...@gmail.com wrote:

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)
     th.start()





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.

Have you tried checking the return code from subprocessor.call(), or sending the subprocess's stdout and stderr to file? It's probably best if you don't run the thread in an infinite loop when you do that. Why are you doing that anyway?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to