Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tornado web server with unix socket support
import tornado.ioloop
import tornado.web
from tornado.httpserver import HTTPServer
from tornado.options import options, define
from tornado.netutil import bind_unix_socket
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()
@codeskyblue

This comment has been minimized.

Copy link

@codeskyblue codeskyblue commented Jun 23, 2016

missing from tornado.netutil import bind_unix_socket

@superduper

This comment has been minimized.

Copy link
Owner Author

@superduper superduper commented Feb 7, 2017

@codeskyblue good point

@xyz666

This comment has been minimized.

Copy link

@xyz666 xyz666 commented Mar 24, 2017

missing from tornado.httpserver import HTTPServer

@kitianFresh

This comment has been minimized.

Copy link

@kitianFresh kitianFresh commented Sep 11, 2017

Is there any http client example?

@spaceone

This comment has been minimized.

Copy link

@spaceone spaceone commented Jun 5, 2019

@kitianFresh A example of a unix socket client is in: tornadoweb/tornado#2671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.