def connecho(): c = yield bluelet.connect("127.0.0.1", 4915) while True: yield c.sendall("HELLO WORLD") data = yield c.recv(1024) print("SERVER:", data) raw_input("HEY")
def communicate(self): conn = yield bluelet.connect(self.host, self.port) yield cw._sendmsg(conn, cw.WorkerRegisterMessage()) connected = True try: while True: # Get a task from the master. msg = yield cw._readmsg(conn) if msg is None: print('connection to master closed') connected = False break assert isinstance(msg, cw.TaskMessage) try: with chdir(msg.cwd): func = cw.func_deser(msg.func_blob) args = cw.slow_deser(msg.args_blob) kwargs = cw.slow_deser(msg.kwargs_blob) res = func(*args, **kwargs) except: res = format_remote_exc() response = cw.ResultMessage(msg.jobid, False, cw.slow_ser(res)) else: response = cw.ResultMessage(msg.jobid, True, cw.slow_ser(res)) yield cw._sendmsg(conn, response) finally: if connected: yield cw._sendmsg(conn, cw.WorkerDepartMessage())
def connecho(): c = yield bluelet.connect("127.0.0.1", 8000) game_finish = False while ~game_finish: yield c.send("Ana are mere".encode()) data = c.recv(1024) print("SERVER:", data)
def handle_results(self, callback): self.conn = yield bluelet.connect(self.host, self.port) self.connection_ready() while True: result = yield cw._readmsg(self.conn) if result is None: print('server connection closed') return assert isinstance(result, cw.ResultMessage) callback(result.jobid, result.success, cw.slow_deser(result.result_blob))
def channel(port=4915): # Create a pair of connected sockets. connections = [None, None] listener = bluelet.Listener('127.0.0.1', port) def listen(): connections[0] = yield listener.accept() # Avoiding nonlocal. listen_thread = listen() yield bluelet.spawn(listen_thread) connections[1] = yield bluelet.connect('127.0.0.1', port) yield bluelet.join(listen_thread) # Wrap sockets in Endpoints. sentinel = uuid.uuid4().bytes # Somewhat hacky... yield bluelet.end((Endpoint(connections[0], sentinel), Endpoint(connections[1], sentinel)))
def communicate(self): conn = yield bluelet.connect(self.host, self.port) yield cw._sendmsg(conn, cw.WorkerRegisterMessage()) connected = True try: while True: # Get a task from the master. msg = yield cw._readmsg(conn) if msg is None: print('connection to master closed') connected = False break assert isinstance(msg, cw.TaskMessage) try: with chdir(msg.cwd): func = cw.func_deser(msg.func_blob) args = cw.slow_deser(msg.args_blob) kwargs = cw.slow_deser(msg.kwargs_blob) res = func(*args, **kwargs) except Exception as exception: # Check if the function tells us to shut down this worker. # We can't just catch the exception normally - # for some reason between serialization things get # fouled up. if type(exception).__name__ == 'ShutdownSignal': res = 'shutdown signal received' response = cw.ResultMessage( msg.jobid, True, cw.slow_ser(res), True) yield cw._sendmsg(conn, response) break res = format_remote_exc() response = cw.ResultMessage(msg.jobid, False, cw.slow_ser(res), False) else: response = cw.ResultMessage(msg.jobid, True, cw.slow_ser(res), False) yield cw._sendmsg(conn, response) finally: if connected: yield cw._sendmsg(conn, cw.WorkerDepartMessage())
def _connect(self): self.conn = yield bluelet.connect(self.host, self.port)