Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info

    I developed one of the demo programs (chat)
    But the problem I encountered is that I can't display a image(url) in the tepmplate html
    in index.html i have

    class MessageNewHandler(BaseHandler):
    """Post a new message to the chat room."""
    def post(self):
    img_url = UsernameFinder.find_Avatr(self)

        name = UsernameFinder.find_screenName(self)
        body= self.get_argument("body")
        message = {"id": str(uuid.uuid4()), "img_url": str(img_url) ,"name": name ,"body":body}
        #message = {"id": str(uuid.uuid4()), "img_url":img_url ,"name": name ,"body":body}
        message["html"] = tornado.escape.to_unicode(
            self.render_string("message.html", message= message)
        if self.get_argument("next", None):
            #name = tornado.escape.xhtml_escape(self.current_user)

    Now how can I show img_url , and name and body in seperate <td>


    Does anyone have a good reading resource about async coroutines in tornado?

    I’m searching for a sample of a coroutine added to what is documented in tornado.locks.
    My test throws the widely discoussed was never awaitederror. But helpful resources are always for pythonic not tornado solutions...


    Does anyone have a good reading resource about async coroutines in tornado?

    I’m searching for a sample of a coroutine added to what is documented in tornado.locks.
    My test throws the widely discoussed was never awaitederror. But helpful resources are always for pythonic not tornado solutions...

    the doc’s have that documented in a other section: https://www.tornadoweb.org/en/stable/guide/coroutines.html
    I did not see that.

    Well it turns out to not be quite complet.
    Does anyone know the tornado equivalent of:
    loop = asyncio.new_event_loop()
    Bruno P. Kinoshita
    @novski I think they have that documented in their IOLoop section of the docs https://www.tornadoweb.org/en/stable/ioloop.html
    Luke Hinds
    what's the current method of seeing incoming requests in tornado - namely the full url called if possible?
    Luke Hinds
    I can see self.request , but would like the whole thing is possible
    Hi guys. Sorry for asking. But I've read tons of stackoverflow examples and other explanations from sites. Still not sure if I'm doing right thing with semi-long running blocking task. https://stackoverflow.com/questions/61516148/write-back-through-the-callback-attached-to-ioloop-in-tornado. I know you tired solving peoples obvious mistakes. But I tried to minimize amount of stupid mistakes. And understand that my blocking DB and IO calls aren't asynchronous and should be managed in Thread or being delegated into a worker. Yet. Do you see any flaws, or maybe I'm doing something completely wrong? Thanks a lot!
    @lukehinds self.request.full_url() works for me
    @kaldown I've commented on your SO question.
    @zejn thank you. I responded :)
    Still I think it would be better to create global ThreadPoolExecutor then set it to ioloop and then use via interface, without being afraid to create fork bomb calling some inner code with the different ThreadPoolExecutor instance
    Sure. That obviously depends on what you are trying to achieve, eg. you can have one global executor, but use another for something very specific.
    The problem is exactly in cross computations. We have old self written framework to handle DB queries with mongodb, using ThreadPoolExecutor. I'm curious if calling that queries from withing this blocking function handler would be a huge mistake.
    Hey people, I need some advice, perhaps somebody can help. I am implementing simple Sign-up/ Log-in functionalities on my page and I want to connect it to database (meaning, when user signs up, I want to store his credentials in my database and to look it up from db when he wants to log in). Furthermore, user should be able to save some data, and access it later. Now, I am not sure which DBMS to use. Is it better to be SQL-ish like (PostgreSQL with AIOPG) or is it MongoDB (with Motor library for asynchronous style) better way to go? Many thanks!
    Robbie Capps
    I use Firebase from Google
    There's a Python SDK
    Also a good open source api wrapper called pyrebase
    Zachary LeFevre
    Is there any way to measure request latency (including time waiting to be handled?
    @zachlefevre you can override the on_finish method and add there your logic to measure the duration of a handler
    @zachlefevre a built-in method self.request.request_time()
    hello, guys ~
    Is there a trick could inject an obj into each tornado handlers ?
    one I knew is let it in my basehandler, Is there others?
    Why did I use tornado.gen.sleep(2) in async def get() work,but asyncio.sleep(2) not work?
    Why did I use tornado.gen.sleep(2) in async def get() work,but asyncio.sleep(2) not work?
    raise loop = events.get_running_loop() RuntimeError: no running event loop
    hello, is there a way to get the full path of a template inside the template itself ?
    If I have in a handler this self.render('login.html')
    and in login.html I put something like this {{ __name__ }} I get login_html on the browser
    the only reason I want this is to display extra "debugging" information for other devs when working on a development env.
    Rick Nitsche
    is there a way to tell Tornado about the URL root of my web app?
    I am supplying an authentication module with auth_provider, if I set the login_url in there to /login, the login page is correctly served on host/rooturl/login, but If I access host/rooturl with my browser, I get redirected to host/login.
    Now if I set login_url to /urlroot/login, it gets served at host/urlroot/urlroot/login.
    Naveen Michaud-Agrawal
    can't find this anywhere, but can't Tornado's StaticFileHandler serve already gzipped resources (with the appropriate encoding headers)?
    Kirill Plotnikov
    Hi everyone! Could you please tell me what is the best and most modern way to connect tornado server to Redis? I found libs like tornado-redis, toredis, brukva but it seems like they are not maintained anymore. Will something like aioredis, aredis, asyncio_redis work properly with tornado? Are there any caveats? Thanks in advance!
    Kirill Plotnikov
    Looks like tornado works well with aredis.
    Marko Mrdjenovic
    @pltnk unless you're using long-running stuff in redis, you're good with redis-py
    even if you do, I'd suggest you use redis-py for fast, sync stuff

    Hey. Im running a mozilla-webthing-python that is built upon tornado and i have it on a small IOT Device that has GPIO. It supports intel MRAA Framework and i use it with a interrupt function.

    Too much informaiton?
    Well just forget the details. The Problem i walked in to is that it generates a new thread and im wondering how i can reach the MainThread again?
    Any ideas?

    tornado.ioloop.IOLoop.current().time() is 1h behind my real time. How to convert to local time?
    Patrick Woo

    hello, is there a way to just gzip compress requests for static assets? this setting

    --NotebookApp.tornado_settings='{ "compress_response": True }’

    seems to compress all requests not just requests for js and css assets

    Bruno P. Kinoshita
    @agileurbanite not tested, but maybe you could try modifying the request handler _transforms of a custom static file handler. And just add a GZip transformer as in the application
    hi, does tornadoweb requires the ctype python module?
    Ivan Trusov

    Hi everyone,

    I'm trying to use tornado App + socket.io for some tunneling.
    Imagine I would like to do the following - on every connection coming from the socket.io, I would like to add a new coroutine to the tornado loop. Coroutine method looks like this:

        async def read_routine(self):
            logging.info("Starting reading routine")
            while True:
                    if self.stream:
                        data = await self.stream.read_bytes(1024)
                        await self.io.emit("response", {"data": data})
                except Exception as e:
                    logging.error(f"Reading routine stopped with error {e}")

    I'm trying to add this callback to the ioloop:

        app = tornado.web.Application(
                (r"/health", MainHandler),
                (r"/socket.io/", socketio.get_tornado_handler(handler.io)),
        app_port = 6006
        loop = tornado.ioloop.IOLoop.current()
        logging.info(f"starting server on port {app_port}")

    But it blocks the execution on the add_callback operation, so the application never starts. How to fix this?

    2 replies
    Thomas Grainger
    @bdarnell is there a way to use TCPServer.start in python3.10 without DeprecationWarnings ?
    looks like you have to do:
                sockets = bind_sockets(8888)
                server = TCPServer()
                async def amain():
                    await asyncio.Event.wait()
    Thomas Grainger
    ok this works for me
    import asyncio
    import tornado.web
    from tornado.ioloop import IOLoop
    from tornado.netutil import bind_sockets, add_accept_handler, ssl_wrap_socket
    from tornado import process
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello, world")
    def make_app():
        return tornado.web.Application([
            (r"/", MainHandler),
    def main():
        app = make_app()
        server = tornado.httpserver.HTTPServer(app)
        sockets = bind_sockets(8889)
        async def amain():
            await asyncio.Event().wait()
    if __name__ == "__main__":
    maybe it would make sense to add a TCPServer.start_and_run() method?
    Michał Gandor

    Hi everyone,

    I have some doubts about login handling. When a session is lost in my app, redirection is made to the login page with next param set by default by tornado containing the last page visited.
    Next can be easily got in GET method of my handler, that's fine. On the login page (where the user is redirected after session lost) I have a login form sending user data via post method. In my handler in def post method is it not possible to retrieve the next param. What is the best flow to redirect user to the desired page after sending POST with form on login?

    Alejandro Mora
    Hi, everybody, how do you apply Dependency Injection in yours proyects with Tornado? i'm wondering propper way to do that, so i would like to know your opinions about that
    I'm looking to do a chat application for an existing tornado server - should i be using websocket or server push? Any example code out there that might help?
    @renardeinside websocket is better suited wrt updates, connection detection etc. A lot of chat apps in php also use smart ajax.
    Sorry* @interviewer_gitlab
    I have a question. Does the execution speed benifits that come with the new python 3.11 affect tornado in any way ?
    1 reply
    If I define a get or post handler as async does Tornado automatically know to await it before closing the connection? Is there a version of Tornado I need to look for in order to ensure it knows what to do with the returned Future?