def __proc(self, op, args, kwargs): res = '' func = getattr(self, op) if func: ret = func(*args, **kwargs) if ret: res = ret return dumps({'res':res})
def __proc(self, op, args, kwargs): res = '' func = getattr(self, op) if func: ret = func(*args, **kwargs) if ret: res = ret return dumps({'res': res})
def _request(self, addr, **args): sock = io.connect(addr, WORKER_PORT) try: buf = bson.dumps(args) io.send_pkt(sock, buf) res = io.recv_pkt(sock) return unicode2str(bson.loads(res)['result']) finally: io.close(sock)
def put(addr, port, code, args): if not code or type(args) != dict: raise Exception('Error: cannot process') sock = io.connect(addr, port) try: buf = bson.dumps({'code':code, 'args':args}) io.send_pkt(sock, buf) res = io.recv_pkt(sock) return unicode2str(bson.loads(res)['']) finally: io.close(sock)
def handle(self): try: res = '' buf = io.recv_pkt(self.request) if buf: req = unicode2str(bson.loads(buf)) if type(req) == dict: device = _manager.compute_unit ret = _exec(device, req['code'], **req['args']) if ret: res = ret io.send_pkt(self.request, bson.dumps({'':res})) except: pass
def pack(op, args, kwargs): if type(op) != str or type(args) != tuple or type(kwargs) != dict: log_err('package', 'failed to pack, invalid type') return buf = {'op': op, 'args': args, 'kwargs': kwargs} return dumps(buf)