From: Ben Darnell Date: Sun, 6 Oct 2013 00:38:39 +0000 (-0400) Subject: Polish for extra debug-mode settings. X-Git-Tag: v3.2.0b1~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd3d1919e7301349fcc117b03123622f88b31f84;p=thirdparty%2Ftornado.git Polish for extra debug-mode settings. Split template_cache into two settings, for template and static files. Rename several options. Update docs. --- diff --git a/docs/overview.rst b/docs/overview.rst index 6bd6ca0d2..a85a970eb 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -972,26 +972,30 @@ Debug mode and automatic reloading If you pass ``debug=True`` to the ``Application`` constructor, the app will be run in debug/development mode. In this mode, several features -intended for convenience while developing will be enabled: - -* The app will watch for changes to its source files and reload itself - when anything changes. This reduces the need to manually restart the - server during development. However, certain failures (such as syntax - errors at import time) can still take the server down in a way that - debug mode cannot currently recover from. -* Templates will not be cached, nor will static file hashes (used by the - ``static_url`` function) -* When an exception in a ``RequestHandler`` is not caught, an error - page including a stack trace will be generated. - -Debug mode is not compatible with ``HTTPServer``'s multi-process mode. +intended for convenience while developing will be enabled (each of which +is also available as an individual flag; if both are specified the +individual flag takes precedence): + +* ``autoreload=True``: The app will watch for changes to its source + files and reload itself when anything changes. This reduces the need + to manually restart the server during development. However, certain + failures (such as syntax errors at import time) can still take the + server down in a way that debug mode cannot currently recover from. +* ``compiled_template_cache=False``: Templates will not be cached. +* ``static_hash_cache=False``: Static file hashes (used by the + ``static_url`` function) will not be cached +* ``serve_traceback=True``: When an exception in a ``RequestHandler`` + is not caught, an error page including a stack trace will be + generated. + +Autoreload mode is not compatible with ``HTTPServer``'s multi-process mode. You must not give ``HTTPServer.start`` an argument other than 1 (or -call `tornado.process.fork_processes`) if you are using debug mode. +call `tornado.process.fork_processes`) if you are using autoreload mode. The automatic reloading feature of debug mode is available as a standalone module in ``tornado.autoreload``. The two can be used in combination to provide extra robustness against syntax errors: set -``debug=True`` within the app to detect changes while it is running, +``autoreload=True`` within the app to detect changes while it is running, and start it with ``python -m tornado.autoreload myserver.py`` to catch any syntax errors or other errors at startup. diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 7fc1fc359..79cccb498 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -16,13 +16,15 @@ """xAutomatically restart the server when a source file is modified. -Most applications should not access this module directly. Instead, pass the -keyword argument ``debug=True`` to the `tornado.web.Application` constructor. -This will enable autoreload mode as well as checking for changes to templates -and static resources. Note that restarting is a destructive operation -and any requests in progress will be aborted when the process restarts. -(If you want to disable autoreload while keeping debug on pass in also the -keyword argument ``autoreload=False``). +Most applications should not access this module directly. Instead, +pass the keyword argument ``autoreload=True`` to the +`tornado.web.Application` constructor (or ``debug=True``, which +enables this setting and several others). This will enable autoreload +mode as well as checking for changes to templates and static +resources. Note that restarting is a destructive operation and any +requests in progress will be aborted when the process restarts. (If +you want to disable autoreload while using other debug-mode features, +pass both ``debug=True`` and ``autoreload=False``). This module can also be used as a command-line wrapper around scripts such as unit test runners. See the `main` method for details. @@ -40,6 +42,7 @@ Reloading loses any Python interpreter command-line arguments (e.g. ``-u``) because it re-executes Python using ``sys.executable`` and ``sys.argv``. Additionally, modifying these variables will cause reloading to behave incorrectly. + """ from __future__ import absolute_import, division, print_function, with_statement diff --git a/tornado/web.py b/tornado/web.py index 7692de753..b820d9645 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -889,7 +889,7 @@ class RequestHandler(object): else: self.finish(self.get_error_html(status_code, **kwargs)) return - if self.settings.get("debug_traceback") and "exc_info" in kwargs: + if self.settings.get("serve_traceback") and "exc_info" in kwargs: # in debug mode, try to send a traceback self.set_header('Content-Type', 'text/plain') for line in traceback.format_exception(*kwargs["exc_info"]): @@ -1500,8 +1500,9 @@ class Application(object): if self.settings.get('debug'): self.settings.setdefault('autoreload', True) - self.settings.setdefault('template_cache', False) - self.settings.setdefault('debug_traceback', True) + self.settings.setdefault('compiled_template_cache', False) + self.settings.setdefault('static_hash_cache', False) + self.settings.setdefault('serve_traceback', True) # Automatically reload modified modules if self.settings.get('autoreload') and not wsgi: @@ -1665,10 +1666,11 @@ class Application(object): # If template cache is disabled (usually in the debug mode), # re-compile templates and reload static files on every # request so you don't need to restart to see changes - if not self.settings.get("template_cache"): + if not self.settings.get("compiled_template_cache", True): with RequestHandler._template_loader_lock: for loader in RequestHandler._template_loaders.values(): loader.reset() + if not self.settings.get('static_hash_cache', True): StaticFileHandler.reset() handler._execute(transforms, *args, **kwargs)