- “Tornado” is a Python based framework to create web applications.
- Most important features of this framework are:-
—Asynchronous I/O calls.
—Maximum Polling .
- In this Demo, “We will learn about installing the tornado site package with a simple program listing to a port”.
- To install tornado framework use the PIP tool.Below screenshot shows the detailed command for installation of tornado framework,
- Yo can verify the installation by checking the ‘site-packages‘ directory under python library.Below screenshot shows the installation path,
- Let’ create a python project ‘TornadoWebAppDemo‘ and have a ‘main.py‘ python file as below,
- The main.py file contains the below code,
self.write("Hi Sandeep, Welcome to Tornado Web Framework.")
if __name__ == "__main__":
application = tornado.web.Application([
- About the above code:-
–This is the main method where python start executing.Single point Entry for the program.
–This is the class which creates a base for web application taking a collection of handlers.
–In this Demo “MainHandler” is the single handler mapped to root path.
–Application listen to port 8888.Any client can communicate this application using this port .
–IOLoop class is main event for the application.
–Create a non blocking thread for an application.
–It is singleton in nature.
–It is handler for a request.
— It refers to the current context using ‘self‘.
— Returns the response using write() method.
- We can run the application using command prompt or use any IDE like Eclipse with python or pycharm.
In Command Prompt,
- Below screen shot shows output in the browser,