Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ouestion on Python Loop
#1
Hi All,
I have a question on this python which i have attached below. My question is i want the python script "PIRoncall.py" script to be run once but i want the read file loop to continue,currently it keeps on duplicating and there is mutiple process of "PIRoncall.py" script. I have thought of using shell command for checking process existence (pgrep?) before launching PIRoncall.py instance but i am not sure how to proceed. Anyone please help ?
import time
import subprocess
import os

oldline="none"
while True:
   fh=open("status_mjpeg.txt","r")
   line = fh.read(5)
   print line
   fh.close()
   time.sleep(0.3)
   if oldline !=line:
       if line == "md_re":
            print "on"
            time.sleep(0.2)
            os.system(' /usr/bin/python PIRoncall.py &')
            time.sleep (2)
       elif line == "ready":
            print "on"
            os.system(' /usr/bin/python PIRoffcall.py')
            time.sleep(2)
       oldline = line
Reply


Messages In This Thread
Ouestion on Python Loop - by GOPI56 - Jan-08-2017, 01:25 PM
RE: Ouestion on Python Loop - by Windspar - Jan-08-2017, 01:57 PM
RE: Ouestion on Python Loop - by buran - Jan-08-2017, 02:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020