Tornado – Options

You must have observed, all this while we have written tornado based applications that listen on port 8888, and in MySQL post, we had predefined our database connection details (like server, username, password etc). But what if we need to change these details based on modules or applications or configurations? Tornado, provides this with a module tornado.options.

You could use this module in different ways for different purposes.. Lets see them in detail

Example 1:

This is a basic example where the current module define its options with define() method. For instance, port is defined as define(“port”, default=8888)

Example 2:

It’s always not good to define options for every module separately. Case for some re-usability? Yes, one could define options in a module which can be imported. In this example, all options are defined in that is imported in the main program.

Example 3:

Options can also be defined on command line which is possible via tornado.options.parse_command_line(). In the example below, we pass logging level (info|debug|…) on command line, that the module understands with parse_command_line() method.

Example 4:

Options can also be defined in a config file with tornado.options.parse_config_file(). In this example, we use to define port, host, database with username and password. We also define port in the main program. But the options for port defined in config py takes precedence and GET on http://localhost:8000/db would work but not on port 8888

3 thoughts on “Tornado – Options

  1. With Tornado options module, you can set the log level with –logging=info or debug or warning on the command line..

  2. After looking over a handful of the blog posts on your website, I honestly appreciate your way of
    writing a blog. I bookmarked it to my bookmark webpage list and will be checking back
    in the near future. Please visit my website as well and let me know your

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.