def update_global_data(): current_hour = int(time.strftime('%H', time.localtime(time.time()))) if current_hour == options.scheduler_wakeup_hour: g_logger.info('Scheduler: update_global_data') else: g_logger.info('Scheduler: No Operation') pass
def __init__(self, capacity=10000, delay_time=10, pop_size=1): self.__queue = CircularQueue(capacity=capacity) self.__set = set() self.__DELAY_TIME = delay_time self.__POP_SIZE = pop_size g_logger.info('Capacity: %d, DelayTime: %d', capacity, self.__DELAY_TIME) pass
def main(): ''' main function ''' # 忽略Broken Pipe信号 signal.signal(signal.SIGPIPE, signal.SIG_IGN) # 处理kill信号 signal.signal(signal.SIGINT, handle_signal_kill) signal.signal(signal.SIGQUIT, handle_signal_kill) signal.signal(signal.SIGTERM, handle_signal_kill) signal.signal(signal.SIGHUP, handle_signal_kill) g_logger.info('START TORNADO WEB SERVER ...') for key, option in options.iteritems(): g_logger.info('Options: (%s, %s)', key, option.value()) try: http_server = \ tornado.httpserver.HTTPServer(request_callback=TApplication()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() g_logger.info('STOP TORNADO WEB SERVER ...') except socket.error, e: g_logger.warning('Socket Error: %s' % str(e))
def main(): ''' main function ''' # 忽略Broken Pipe信号 signal.signal(signal.SIGPIPE, signal.SIG_IGN); # 处理kill信号 signal.signal(signal.SIGINT, handle_signal_kill) signal.signal(signal.SIGQUIT, handle_signal_kill) signal.signal(signal.SIGTERM, handle_signal_kill) signal.signal(signal.SIGHUP, handle_signal_kill) g_logger.info('START TORNADO WEB SERVER ...') for key, option in options.iteritems(): g_logger.info('Options: (%s, %s)', key, option.value()) try: http_server = \ tornado.httpserver.HTTPServer(request_callback=TApplication()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() g_logger.info('STOP TORNADO WEB SERVER ...') except socket.error, e: g_logger.warning('Socket Error: %s' % str(e))
def post(self): try: if not self.request.body: return self.api_response({'e_code': ECODE.Q_ERROR, 'e_msg': EMSG.Q_ERROR}) json_obj = tornado.escape.json_decode(self.request.body) g_logger.info(json_obj) if not isinstance(json_obj, dict): return self.api_response({'e_code': ECODE.Q_TYPE_ERROR, 'e_msg': EMSG.Q_TYPE_ERROR}) for k, v in json_obj.iteritems(): result = self.queue.push({'k': k, 'v': v}) if ECODE.Q_FULL == result: break pass self.api_response({'e_code':ECODE.SUCCESS, 'e_msg': 'SUCCESS'}) except HTTPError, e: g_logger.error(e) return self.api_response({'e_code':ECODE.HTTP, 'e_msg': '%s' % e})
def main(): ''' main function ''' # 忽略Broken Pipe信号 signal.signal(signal.SIGPIPE, signal.SIG_IGN) # 处理kill信号 signal.signal(signal.SIGINT, handle_signal_kill) signal.signal(signal.SIGQUIT, handle_signal_kill) signal.signal(signal.SIGTERM, handle_signal_kill) signal.signal(signal.SIGHUP, handle_signal_kill) g_logger.info('START TORNADO WEB SERVER ...') for key, option in options.iteritems(): g_logger.info('Options: (%s, %s)', key, option.value()) try: if sys.version_info[:3] >= (2, 5, 2): #pycurl minimum supported version is 7.18.2 tornado.httpclient.AsyncHTTPClient.configure( "tornado.curl_httpclient.CurlAsyncHTTPClient") pass sockets_list = [] for bind_ip in options.bind_ip.split(','): sockets = tornado.netutil.bind_sockets(options.port, address=bind_ip, backlog=128) sockets_list.append(sockets) #tornado.process.fork_processes(0) global g_scheduler g_scheduler = \ tornado.ioloop.PeriodicCallback(update_global_data, options.scheduler_interval * 1000) g_scheduler.start() http_server = \ tornado.httpserver.HTTPServer(xheaders=True, request_callback=TApplication()) for sockets in sockets_list: http_server.add_sockets(sockets) tornado.ioloop.IOLoop.instance().start() http_server.stop() tornado.ioloop.IOLoop.instance().close() g_logger.info('STOP TORNADO WEB SERVER ...') except socket.error as e: g_logger.warning('Socket Error: %s', e, exc_info=True) except KeyboardInterrupt as e: g_logger.warning('Gently Quit') except Exception as e: g_logger.error('UnCaught Exception: %s', e, exc_info=True)
def main(): ''' main function ''' init_options() init_logger() # 忽略Broken Pipe信号 signal.signal(signal.SIGPIPE, signal.SIG_IGN) # 处理kill信号 signal.signal(signal.SIGINT, handle_signal_kill) signal.signal(signal.SIGQUIT, handle_signal_kill) signal.signal(signal.SIGTERM, handle_signal_kill) signal.signal(signal.SIGHUP, handle_signal_kill) g_logger.info('START TORNADO SERVER ...') for key, option in options.iteritems(): g_logger.info('Options: (%s, %s)', key, option.value()) try: if sys.version_info[:3] >= (2, 5, 2): #pycurl minimum supported version is 7.18.2 AsyncHTTPClient.configure( "tornado.curl_httpclient.CurlAsyncHTTPClient") pass HTTPServer.instance().start() tornado.ioloop.IOLoop.instance().start() HTTPServer.instance().stop() tornado.ioloop.IOLoop.instance().close(all_fds=True) g_logger.info('STOP TORNADO SERVER ...') except socket.error as e: g_logger.warning('Socket Error: %s', e, exc_info=True) except KeyboardInterrupt as e: g_logger.warning('Gently Quit') except Exception as e: g_logger.error('UnCaught Exception: %s', e, exc_info=True)
def main(): ''' main function ''' init_options() init_logger() # 忽略Broken Pipe信号 signal.signal(signal.SIGPIPE, signal.SIG_IGN); # 处理kill信号 signal.signal(signal.SIGINT, handle_signal_kill) signal.signal(signal.SIGQUIT, handle_signal_kill) signal.signal(signal.SIGTERM, handle_signal_kill) signal.signal(signal.SIGHUP, handle_signal_kill) g_logger.info('START TORNADO SERVER ...') for key, option in options.iteritems(): g_logger.info('Options: (%s, %s)', key, option.value()) try: if sys.version_info[:3] >= (2, 5, 2): #pycurl minimum supported version is 7.18.2 AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") pass HTTPServer.instance().start() tornado.ioloop.IOLoop.instance().start() HTTPServer.instance().stop() tornado.ioloop.IOLoop.instance().close(all_fds=True) g_logger.info('STOP TORNADO SERVER ...') except socket.error as e: g_logger.warning('Socket Error: %s', e, exc_info=True) except KeyboardInterrupt as e: g_logger.warning('Gently Quit') except Exception as e: g_logger.error('UnCaught Exception: %s', e, exc_info=True)
def on_connection_close(self): g_logger.info('connection close.') pass
def clean(self): del self.__list[:] g_logger.info('CircularQueue::Clean()') pass
def on_finish(self): '''Require: tornado.version > 2.1.1 ''' request_time = 1000.0 * self.request.request_time() g_logger.info("%d %s %.2fms", self.get_status(), self._request_summary(), request_time)
def initialize(self): if __debug__: g_logger.debug('call initialize()') self.set_header('Server', BaseHandler.HTTP_SERVER_NAME) g_logger.info(HttpUtil.get_header_string(self.request)) pass
def on_connection_close(self): g_logger.info('connection close.')