def tornado_worker(tornado_app, sockets, parent_pid):
"""
Tornado worker which process HTTP requests.
"""
setproctitle.setproctitle(
"{:s}: worker {:s}".format(
tornado_app.settings['context'].config.name,
tornado_app.settings['interface'].name
)
)
tornado_app.settings['context'].config.configure_logging()
# Run HTTP server
http_server = tornado.httpserver.HTTPServer(tornado_app)
http_server.add_sockets(sockets)
# Register SIGINT handler which will stop worker
def sigint_handler(dummy_signum, dummy_frame):
"""
Stop HTTP server and IOLoop if SIGINT.
"""
# Stop HTTP server (stop accept new requests)
http_server.stop()
# Stop IOLoop
tornado.ioloop.IOLoop.instance().add_callback(
tornado.ioloop.IOLoop.instance().stop)
signal.signal(signal.SIGINT, sigint_handler)
# Register job which will stop worker if parent process PID is changed
stop_callback = tornado.ioloop.PeriodicCallback(
functools.partial(stop_child, http_server, parent_pid), 250)
stop_callback.start()
# Run IOLoop
tornado.ioloop.IOLoop.instance().start()
评论列表
文章目录