def log_message(self, *args, **kwargs): # disable built-in response logging pass def _log_request(self): current_time = self.date_time_string() self._request_count += 1 logging.info( "client_address:{client_address}, request_count:{request_count}, current_time:{current_time}" .format(client_address=self.client_address, request_count=self._request_count, current_time=current_time)) def sigterm_handler(*args): logging.info('Received SIGTERM, gracefully shutdown now') global shutdown_requested shutdown_requested = True _thread.start_new_thread(lambda svc: svc.shutdown(), (httpd, )) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) signal.signal(signal.SIGTERM, sigterm_handler) server_address = ('0.0.0.0', 8080) httpd = ThreadingHTTPServer(server_address, RequestHandler) httpd.daemon_threads = False httpd.serve_forever()
params['results'] = json.dumps(rsp) params['apiinfo'] = json.dumps({k:str(v) for k,v in api._ratelimit.items()}) except ZohoException as e: params['results'] = json.dumps({ 'Exception': { 'class': e.__class__.__name__, 'message': str(e), 'traceback': [l for l in traceback.format_exc().split('\n')] } }) return self.do_GET() if __name__ == "__main__": server = ThreadingHTTPServer((hostName, serverPort), RequestHandler) server.daemon_threads = True server.allow_reuse_address = True def signal_handler(signal, frame): print("Exiting due to keyboard interrupt...") try: if (server): server.server_close() finally: sys.exit(0) signal.signal(signal.SIGINT, signal_handler) print(f"Server started http://{hostName}:{serverPort}") print("Press Ctrl-C to exit.") system("title pyZohoAPI Testing Server")