From 26cb426807ac77e32e3450d2e294015465ac99e9 Mon Sep 17 00:00:00 2001 From: Juraj Niznan Date: Wed, 4 Sep 2013 15:36:00 +0200 Subject: [PATCH] possibility to disable autoreload when debug is on --- tornado/autoreload.py | 2 ++ tornado/process.py | 3 ++- tornado/tcpserver.py | 3 ++- tornado/web.py | 14 ++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tornado/autoreload.py b/tornado/autoreload.py index 05754299a..7fc1fc359 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -21,6 +21,8 @@ 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``). This module can also be used as a command-line wrapper around scripts such as unit test runners. See the `main` method for details. diff --git a/tornado/process.py b/tornado/process.py index ffd2d29d5..942c5c3f6 100644 --- a/tornado/process.py +++ b/tornado/process.py @@ -92,7 +92,8 @@ def fork_processes(num_processes, max_restarts=100): between any server code. Note that multiple processes are not compatible with the autoreload - module (or the debug=True option to `tornado.web.Application`). + module (or the ``autoreload=True`` option to `tornado.web.Application` + which defaults to True when ``debug=True``). When using multiple processes, no IOLoops can be created or referenced until after the call to ``fork_processes``. diff --git a/tornado/tcpserver.py b/tornado/tcpserver.py index 8473a21ad..c07737329 100644 --- a/tornado/tcpserver.py +++ b/tornado/tcpserver.py @@ -180,7 +180,8 @@ class TCPServer(object): between any server code. Note that multiple processes are not compatible with the autoreload - module (or the ``debug=True`` option to `tornado.web.Application`). + module (or the ``autoreload=True`` option to `tornado.web.Application` + which defaults to True when ``debug=True``). When using multiple processes, no IOLoops can be created or referenced until after the call to ``TCPServer.start(n)``. """ diff --git a/tornado/web.py b/tornado/web.py index 5f8d6091b..caeb243b1 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -838,7 +838,7 @@ class RequestHandler(object): else: self.finish(self.get_error_html(status_code, **kwargs)) return - if self.settings.get("debug") and "exc_info" in kwargs: + if self.settings.get("debug_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"]): @@ -1447,8 +1447,13 @@ class Application(object): if handlers: self.add_handlers(".*$", handlers) + if self.settings.get('debug'): + self.settings.setdefault('autoreload', True) + self.settings.setdefault('template_cache', False) + self.settings.setdefault('debug_traceback', True) + # Automatically reload modified modules - if self.settings.get("debug") and not wsgi: + if self.settings.get('autoreload') and not wsgi: from tornado import autoreload autoreload.start() @@ -1599,9 +1604,10 @@ class Application(object): if not handler: handler = ErrorHandler(self, request, status_code=404) - # In debug mode, re-compile templates and reload static files on every + # 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 self.settings.get("debug"): + if not self.settings.get("template_cache"): with RequestHandler._template_loader_lock: for loader in RequestHandler._template_loaders.values(): loader.reset() -- 2.47.2