def request(self, method, params=()): """ Request from peer @method: name of method requested @params: tuple params passed to method """ if not isinstance(params, tuple): params = (params,) xmlout = xmlpickler_dumps(params, method) size = len(xmlout) head = BEGIN_XMLREQUEST_HEADER % (self.currid, size) self.send_lock.acquire() #acquire thread lock try: self.session.send(head) self.session.send(xmlout) self.session.send(END_XMLREQUEST_HEADER) has_error = False except Exception, error: has_error = True self.logger.error(error) traceback.print_exc()
def request(self, method, params=()): """ Request from peer @method: name of method requested @params: tuple params passed to method """ if not isinstance(params, tuple): params = (params,) xmlout = xmlpickler_dumps(params, method) size = len(xmlout) head = BEGIN_XMLREQUEST_HEADER % (self.currid, size) self.send_lock.acquire() self.session.send(head) self.session.send(xmlout) self.session.send(END_XMLREQUEST_HEADER) try: self.send_lock.release() except: pass response = Response(self.currid) self.open_responses[self.currid] = response self.currid += 1 return response
def send_response(self, id, response): """ Send Response to peer """ try: output = xmlpickler_dumps((response,), methodresponse=1) head = BEGIN_XMLRESPONSE_HEADER % (id, len(output)) self.send_lock.acquire() self.session.send(head) self.session.send(output) self.session.send(END_XMLRESPONSE_HEADER) except Exception, error: self.logger.error(error)