How the application class implements the Auto-reload function with debug parameters

Source: Internet
Author: User

Code execution process and analysis:

  1. When we instantiate the application class in the main function, we pass in the parameter "Debug=true" (in Python, parameter types such as ' **settings ' allow incoming arguments with parameter names, which is actually incoming dictionary)
    1App =Tornado.web.Application (2Handlers=[(R'/', Indexhandler)],3Template_path=os.path.join (Os.path.dirname (__file__),"Templates"),4Static_path=os.path.join (Os.path.dirname (__file__),"Static"),5debug=True6)
  2. At the same time that the application class is instantiated, its constructor is called, and the following code that is associated with the parameter "Debug=true" is posted for analysis:
    1 ifSelf.settings.get ('Debug'):2Self.settings.setdefault ('Autoreload', True)3Self.settings.setdefault ('Compiled_template_cache', False)4Self.settings.setdefault ('Static_hash_cache', False)5Self.settings.setdefault ('Serve_traceback', True)

    Because the incoming debug value is True, the Self.settings.get (' debug ') function statement is executed sequentially, at which point the value of ' Autoreload ' is set to true, and the value of ' Compiled_template_cache ' is false The value of ' Static_hash_cache ' is false, and the value of ' Serve_traceback ' is true.

  3. Autoreload Module Implementation Auto Restart Server autoreload is set to "True", the constructor of the application class continues with the following function:
1  # automatically reload modified modules 2    if self.settings.get ('autoreload'):3from          Import  autoreload4        Autoreload.start ()

At this point the server tries to restart

4.

In summary, when instantiating the application class, passing in the "debug=true" parameter will implement the dynamic interpretation of the code, Every time when the contents of the. py file are changed, Tornado automatically restarts the server, and we can see the new debugging effect when we refresh the page without having to turn on the server frequently.

Information reference: Http://www.tornadoweb.org/en/stable/web.html#tornado.web.Application

How the application class implements the Auto-reload function with debug parameters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.