How to Start two application on separate IOLoop on the same port In Tornado

340 Views Asked by At
import tornado
from tornado import httpserver
from tornado import web
from tornado.ioloop import IOLoop

class ServiceHandler1(tornado.web.RequestHandler):
    def initialize(self, *args, **kwargs):
        print "service1 handler"

class ServiceHandler2(tornado.web.RequestHandler):
    def initialize(self, *args, **kwargs):
        print "service2 handler"

def main():
    print "started main"
    application1 = web.Application([
        (r"/app1", ServiceHandler1),
        (r"/app2", ServiceHandler2),
    ])
    http_server = httpserver.HTTPServer(application1)
    http_server.listen(8080)

    print "start ioloop"
    tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
    main()
    print "started"

I want to start /app1 in one ioloop and /app2 on a different ioloop so that the calls to these APIs don't block each other

0

There are 0 best solutions below