Tornado Framework

Tornado is a Python web framework and an asynchronous networking library that relies on non-blocking network I/O to serve web applications. This framework is therefore ideal for handling a large number of active server connections, such as in websockets. Tornado also offers built-in internalization, quick request execution, and many other features.

This example illustrates the steps to build a simple Python app with the Tornado framework. This application will then be bundled and associated with an AppSail service, and deployed to the console.

  1. Create a new folder in your local system for the Tornado app.

  2. Navigate to the directory from your terminal and execute the following command to install Tornado:

    
copy
python3 -m pip install tornado -t.
  1. You can now create your python index file and name it app.py or anything of your choice. Add the logic you require in the application’s code. Given below is a sample code for a basic “Hello World” program.
    
copy
import os import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, World!") if __name__ == "__main__": app = tornado.web.Application([ (r"/", MainHandler), ]) listen_port = int(os.getenv('X_ZOHO_CATALYST_LISTEN_PORT', 9000)) app.listen(listen_port, address='0.0.0.0') tornado.ioloop.IOLoop.current().start()
  1. You can now initialize an AppSail service in the same directory from the CLI or add it in an existing project directory. The app’s source must be your application’s directory. Provide the following value while initializing the app service:

    Stack: Python_3_9

  2. Ensure all the Python application files along with the tornado modules are present in the build directory you specify during initialization. Catalyst will automatically ZIP your app files during deployment to the remote console.

  3. Deploy the app service to the console.

  4. You can then configure the startup command given below from the console:

    
copy
python3 -u app.py

You can also configure this in the app-config.json file before deploying.


Access the deployed app service from its endpoint URL.

Last Updated 2023-12-14 16:25:23 +0530 +0530

ON THIS PAGE