def channel_monitor(): ib = InfoBeamerQuery('127.0.0.1') con = ib.node("root").io(raw=True) for line in con: stream_url = line.strip() if stream_url: q.put(stream_url) break for line in con: now_url = line.strip() if now_url != stream_url: break os.kill(os.getpid(), 9)
class Client(Thread): def __init__(self, addr): super(Client, self).__init__() self._addr = addr self._state = "disconnected" self.daemon = True self.start() def run(self): while 1: try: self.reconnect() except InfoBeamerQueryException: time.sleep(0.2) continue try: while 1: line = self._io.readline().strip() if not line: break self._state = line except KeyboardInterrupt: break except Exception: print "something went wrong. reconnecting" self._state = "disconnected" traceback.print_exc() time.sleep(1) def reconnect(self): self._io = InfoBeamerQuery(self._addr).node("videowall").io(raw=True) def send(self, **data): self._io.write(json.dumps(data) + "\n") self._io.flush() self._state = "waiting for confirmation" @property def state(self): return self._state
def reconnect(self): self._io = InfoBeamerQuery(self._addr).node("videowall").io(raw=True)