Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tornado : support multiple Application on same IOLoop

I'm wondering if it is possible in the Tornado framework to register multiple Application on the same IOLoop ?

Something like

application1 = web.Application([
    (r"/", MainPageHandler),
])
http_server = httpserver.HTTPServer(application1)
http_server.listen(8080)

application2 = web.Application([
    (r"/appli2", MainPageHandler2),
])
http_server2 = httpserver.HTTPServer(application2)
http_server2.listen(8080)

ioloop.IOLoop.instance().start()

Basically I'm trying to structure my webapp so that:

  1. functional applications are separated
  2. multiple handlers with the same purpose (e.g. admin/monitoring/etc) are possible on each webapp
like image 823
oDDsKooL Avatar asked Jun 07 '12 15:06

oDDsKooL


1 Answers

The simple thing is if you were to bind your applications to different ports:

...
http_server = httpserver.HTTPServer(application1)
http_server.listen(8080)    # NOTE - port 8080

...
http_server2 = httpserver.HTTPServer(application2)
http_server2.listen(8081)   # NOTE - port 8081

ioloop.IOLoop.instance().start()

This is the base case that Tornado makes easy. The challenge is that by routing to applications at the URI level you're crossing a design boundary which is that each application is responsible for all of the URIs that that are requested by it.

If they all really need to be serviced at the URI level not port, it would probably be best to host different applications on different ports and have Nginx/Apache do the URI routing - anything that involves messing with the Application/Request handling is going to be a world of hurt.

like image 172
koblas Avatar answered Sep 23 '22 13:09

koblas