def push(self, obj, throwOnError = True): #prof.enter("PUSH") debug("Pushing to "+self.name,2) sock = self._connect() chan = sock.makefile("rwb") network.sendString(chan, json.dumps(obj)) debug("Awaiting reply...",2) answ = network.readString(chan) or "SOCK_TIMEOUT" try: self._close(sock) except: pass if(answ != network.OK): if(throwOnError): error("Push failure", 0) error("Refer to supervisor log for details", 0) error("Err was:"+answ,0) return False ok("Configuration "+ obj["workername"] + "("+ obj["jobname"]+") on " + self.name) return answ
def setup(self, data): self.debug_boxing = False if type(data) == type({}): self.debug_boxing = data.get("debug_boxing") config = b"cfg/yolo9000.cfg" weights = b"weights/yolo9000.weights" meta = b"cfg/combine9k.data" self.detector = Detector(config, weights, meta) ok("Starting boxing identifier.") debug("cfg="+str(config)+" weights="+str(weights)+" meta="+str(meta), 3)
def loop(self, packet): try: packet = build_packet(packet) for client in clients_debug: client.sendMessage( bson.dumps({ "meta": packet.data, "img": packet.img })) for client in clients: client.sendMessage(bson.dumps({"meta": packet.data})) except: ok("Terminated.") self.shouldStop = True
def _listenTarget(self): self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.server.bind(('', config.SUPERVISOR_PORT)) self.server.listen(4) ok("Started Supervisor Server") while (self.running): client, addr = self.server.accept() debug("Connection from " + str(addr), 1) Thread(target=self._clientTarget, args=(client, )).start() except: error("Supervisor Server Shutting down") traceback.print_exc() self.server.close() suicide()
def action_halt(self): ok("[HALT] Worker terminated.") suicide()
for k in fd: d += k.strip() fd.close() return d ################## MAIN if __name__ == '__main__': sys.stdout = SupervisedProcessStream(sys.stdout, "MASTER") sys.stderr = SupervisedProcessStream(sys.stderr, "MASTER") #prof.enter("main") ok("Starting Master...") cfg = None if(len(sys.argv) > 1): debug("Using config file: "+str(sys.argv[1]), 2) fil = sys.argv[1] cfg = read(fil) debug(cfg, 3) if(cfg == None): debug("Master started, awaiting config", 1) cfg = input().strip() debug("Reading config...") try: rSup = loadSupervisors(cfg)
def start_server(port): ok("Web Socket server on " + str(port) + " [STARTED]") server = SimpleWebSocketServer('', port, WSserver) server.serveforever()