Beispiel #1
0
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))
Beispiel #2
0
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))
Beispiel #3
0
def handle_signal_kill(sig, frame):
    global g_scheduler

    g_logger.warning('Catch SIG: %d' % sig)

    if g_scheduler is not None:
        g_scheduler.stop()

    tornado.ioloop.IOLoop.instance().stop()
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
def handle_signal_kill(sig, frame):
    g_logger.warning( 'Catch SIG: %d' % sig )

    tornado.ioloop.IOLoop.instance().stop()
Beispiel #8
0
def handle_signal_kill(sig, frame):
    g_logger.warning('Catch SIG: %d' % sig)

    tornado.ioloop.IOLoop.instance().stop()
Beispiel #9
0
    # 处理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))
    except KeyboardInterrupt, e:
        g_logger.warning('Gently Quit')
    except Exception, msg:
        g_logger.error('UnCaught Exception: %s' % msg)
        raise


if __name__ == '__main__':
    main()
Beispiel #10
0
                        
    # 处理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))
    except KeyboardInterrupt, e:
        g_logger.warning('Gently Quit')
    except Exception, msg:
        g_logger.error('UnCaught Exception: %s' % msg)
        raise 

if __name__ == '__main__':
    main()