tornado Getting started with tornado

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

Tornado is a Python web framework and asynchronous networking library, that uses non-blocking network I/O which allows it to scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.

Versions

Hello World

# hello_server.py
import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

    def make_app():
        return tornado.web.Application([ (r"/", MainHandler), ])  # URL Mapping

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)    # Port Number
    tornado.ioloop.IOLoop.current().start()
 

This App is run by typing python3 hello_server.py or python hello_server.py depending on the version of Python being used.
When run locally the server can be accessed by going to 127.0.0.1:8888 from the browser.
The server will return "Hello World".
In make_app() function, the root / is mapped to MainHandler . This means that requests to the root IP 127.0.0.1:8888 will be mapped to the MainHandler function.

Installation or Setup

Python3 - sudo pip3 install tornado
Python2 - sudo pip install tornado

Packages which will are optional but recommended to install alongside Tornado :



Got any tornado Question?