title: Python Linux - Is-Alive Midori Watchdog
body: <p>I am trying to implement a watchdog that will ping a host, if it is up then it will get midori to open the remote page, if not, then it will open a local page.</p>
  
  <p>I have adapted this from the code here: <a href="https://raspberrypi.stackexchange.com/questions/6981/auto-refresh-for-midori">https://raspberrypi.stackexchange.com/questions/6981/auto-refresh-for-midori</a>.</p>
  
  <p>The problem is it only appears to work once for each condition, for example, if the remote site is up, then the remote page is shown, when it goes down, the local page is shown, but when the remote goes up again, midori does not load the page.</p>
  
  <p>I have disabled the midori calls and just outputted the up and last vars, and they are correct and the if conditions are executing correctly, so it looks like it is related to the popen and sub.calls.</p>
  
  <p>Any ideas on what the issue may be ??</p>
  
  <pre><code>#!/usr/bin/env python
  host = "localhost"
  port = 888
  recheck_time = 10
  page_to_open_to = "/"
  lurl = "///usr/share/scripts/splash.htm"
  last = -1 #undefined state
  up = -1 #Undefined state
  
  import subprocess as sub
  from time import sleep
  import socket
  import threading
  
  sub.Popen(["midori", "-a","localhost:888","-e","Fullscreen"]) #open midori
  
  #Check if internet is up
  addr = (host, port) #the connection addr
  
  while True:
      last = up #reset checking var
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #create socket
      try: #attempt to ping, change vars
          s.connect(addr)
          up = 1
  
      except socket.error:
          up = 0 
  
      if up == 1 and last == 0:
          sub.call(["midori", "-a", "localhost:888","-e","Fullscreen"])
          print('up')
  
      elif up == 0 and last == 1:
          sub.call(["midori", "-a",lurl,"-e","Fullscreen"])
          print("down")
  
      s.close()
  
      print(up,",",last)
      sleep(recheck_time)
  </code></pre>
  
  <p>it appears that each time sub.call() is made a new process starts untill there are 2 processes, then nothing:</p>
  
  <pre><code>root      3499  0.3  0.5  10792  5856 tty1     S    17:44   0:00 /usr/bin/python /usr/share/scripts/midori.py
  root      3500  3.3  4.7 191620 48240 tty1     Sl   17:44   0:03 midori -a localhost:888 -e Fullscreen
  root      3530  1.0  2.8 173732 28836 tty1     Sl   17:45   0:00 midori -a ///usr/share/scripts/splash.htm
  </code></pre>