-
-
Save wklken/c5bf3d1a2bb1b9cc6d16 to your computer and use it in GitHub Desktop.
Tornado web server with unix socket support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
from tornado.options import options, define | |
from tornado.netutil import bind_unix_socket | |
from tornado.httpserver import HTTPServer | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
define('listen_address', group='webserver', default='127.0.0.1', help='Listen address') | |
define('listen_port', group='webserver', default=8888, help='Listen port') | |
define('unix_socket', group='webserver', default=None, help='Path to unix socket to bind') | |
if __name__ == "__main__": | |
if options.unix_socket: | |
server = HTTPServer(application) | |
socket = bind_unix_socket(options.unix_socket) | |
server.add_socket(socket) | |
else: | |
application.listen(options.listen_port, address=options.listen_address) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment