简体   繁体   中英

killing or stopping the python script in lettuce

I have a python script it sends data permanently and after seeing its output I want to stop or kill the python script .in lettuce I couldn't manage to kill python script.Any idea for this? I tried that:

os.system('pgrep -f sample.py')
    time.sleep(3.0)
 os.system('pkill -9 -f sample.py')

Try subprocess, its much more clean and elegant the command output can be read via the p.communicate() after executing the command.

p = subprocess.Popen(['pgrep', '-f', 'sample.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pid = p
time.sleep(3.0)
os.kill(pid=pid, sig=9)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM