user
user

Reputation: 71

why python tornado request do not show in browser?

i try to run simple tornado code. but do not see anything in browser . i should see response of function if all would go in correct way. i install old version of tornado using

pip install tornado==4.5.3

i run the code and try to access it in browser using

http://localhost:8826/A
http://localhost:8826/B

console prints

in __main__ 01
in __main__ 02
in __main__ 03
in __main__ 04
in __main__ 05

my code

import nest_asyncio

nest_asyncio.apply()

import tornado.web
from tornado.ioloop import IOLoop
from tornado import gen

from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor   # `pip install futures` for python2



class TestHandler01(tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(max_workers=MAX_WORKERS)

    @tornado.gen.coroutine
    def get(self):
        print("in TestHandler01 get")
        self.write('Response from server01')

class TestHandler02(tornado.web.RequestHandler):
    @gen.coroutine
    def get(self):
        print("in TestHandler02 get")
        self.write('Response from server02')
        self.finish()

if __name__ == '__main__':
    print("in __main__ 01")
    application = tornado.web.Application([
        (r"/A", TestHandler01),
        (r"/B", TestHandler02),
        ])
    print("in __main__ 02")
    application.listen(8826)
    print("in __main__ 03")

    IOLoop.instance().stop()
    print("in __main__ 04")
    IOLoop.instance().start()
    print("in __main__ 05")

Upvotes: 0

Views: 128

Answers (1)

kwarunek
kwarunek

Reputation: 12577

The problem is a IOLoop.stop, before start.

According to the docs (https://www.tornadoweb.org/en/branch4.5/ioloop.html#tornado.ioloop.IOLoop.stop)

If the event loop is not currently running, the next call to start() will return immediately.

Upvotes: 1

Related Questions