在python中停止os.system()启动的进程

时间:2017-01-02 14:48:09

标签: python-2.7 os.system

我目前正在使用raspberry pi制作数据记录系统,我正在使用按钮来启动/停止数据记录。我能够执行python脚本" 3ldrdatalog.py"通过os.system(),但我找不到一个特定的命令来按下第二个按钮上的脚本。

请帮我解释一下代码! 提前致谢

import RPi.GPIO as GPIO
from Adafruit_CharLCD import Adafruit_CharLCD
GPIO.setmode(GPIO.BCM)
GPIO.setup(13,GPIO.IN)
input = GPIO.input(13)
import time
import os
lcd = Adafruit_CharLCD()
#initialise a previous input variable to 0 (assume button not pressed last)
prev_input = 1
try:
   lcd.message('Press button')
   while True:
       #take a reading
       input = GPIO.input(13)

       #if the last reading was low and this one high, print
       if ((not prev_input) and input):
            print("Button pressed")
            lcd.clear()
            #this is the script that will be called (as root)
            os.system("python /home/pi/3ldrdatalog.py")
            #update previous input
            prev_input = input
            #slight pause to debounce
            time.sleep(0.05)
except KeyboardInterrupt:
   file.close()
   pass
finally:
    GPIO.cleanup()         

0 个答案:

没有答案