0
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

user2478236
  • 691
  • 12
  • 32
  • 1
    Err, _what_? You can't have two processes listen on the same port. That's not how ports work. If _something_ is listening on a port, and _something else_ tries to bind it, it should get a PortInUse exception (or whatever the analog is in whatever system / language you're using). – g.d.d.c Feb 13 '19 at 07:15
  • From the tornado docs: https://www.tornadoweb.org/en/stable/guide/running.html "Tornado includes a built-in multi-process mode to start several processes at once. ... This is the easiest way to start multiple processes and have them all share the same port, although it has some limitations." ... ... so it will listen in the main IOLoop, and then divy connections out to child processes, but you don't _actually_ get multiple processes _listening_ on the same port. What you're trying to do _should never work_. That's not how ports work. – g.d.d.c Feb 13 '19 at 07:23
  • thanks for the clarification, will update the code and accordingly and reform my question. – user2478236 Feb 13 '19 at 07:23
  • You can bind a Nginx server to a single port which would redirect certain requests to whatever ports you would require. – Fine Feb 13 '19 at 11:09

0 Answers0