def run(self): trace.info('Accepted client from {}:{}'.format(self.host, self.port)) buf, request = '', '' response = None while True: try: response = self.queue.get_nowait() except Queue.Empty: pass if response: self.handle_response(response) response = None try: data = self.socket.recv(config.MESSAGING_BUFFER_SIZE) if data: buf += data end = buf.find('\n') if end >= 0: request = buf[:end].strip() buf = buf[end + 2:] else: break # Connection closed except socket.timeout: pass if request: self.handle_request(request) request = '' self.socket.close() trace.info('Client {}:{} closed'.format(self.host, self.port))
def run(self): trace.info('Accepted client from {}:{}'.format(self.host, self.port)) buf, request = '', '' response = None while True: try: response = self.queue.get_nowait() except Queue.Empty: pass if response: self.handle_response(response) response = None try: data = self.socket.recv(config.MESSAGING_BUFFER_SIZE) if data: buf += data end = buf.find('\n') if end >= 0: request = buf[:end].strip() buf = buf[end+2:] else: break # Connection closed except socket.timeout: pass if request: self.handle_request(request) request = '' self.socket.close() trace.info('Client {}:{} closed'.format(self.host, self.port))
def handle_request(self, data): try: request = SMAPRequest(data, self) trace.info('Request', request.action.upper(), 'length', len(data)) except (ValueError, KeyError): trace.info('Request length', len(data)) self.queue.put(SMAPResponse('error', reason='bad_request')) else: routes.route_request(request)
def __init__(self): super(MessagingService, self).__init__('messaging') self.counter = 0 self.clients = [] self.lock = Lock() s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((config.MESSAGING_HOST, config.MESSAGING_PORT)) s.listen(config.MESSAGING_MAX_PENDING_CLIENTS) self.socket = s trace.info('Listening on port', config.MESSAGING_PORT)
def run(): threading.current_thread().name = 'main' trace.info('Starting Corpora.') app = threading.Event() def alive(): return not app.is_set() for name in config.SERVICES: service = __import__(name).service service.alive = alive service.start() try: # Block until any key pressed sys.stdin.read() finally: trace.info('Shutting down.') app.set()
def run(self): trace.info('Service started.') while self.alive(): request = self.wait() self.handle(*request)
def handle_response(self, response): data = str(response) + '\n' trace.info('Response', response.status.upper(), 'length', len(data)) self.socket.sendall(data)
def test__trace(): trace.error("Here is the Error Information!!") trace.warning("Here is the Warning Information") trace.info("Here is the Trace Information") trace.debug("Here is the Debug Information")