Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid creating multiple redundant autoreload callbacks.

  • Loading branch information...
commit 50e0a97fb09ef43d7addba396fb181893a5b0b54 1 parent 773cbf6
@bdarnell bdarnell authored
Showing with 15 additions and 6 deletions.
  1. +11 −6 tornado/autoreload.py
  2. +4 −0 website/sphinx/releases/next.rst
View
17 tornado/autoreload.py
@@ -74,6 +74,7 @@
import traceback
import types
import subprocess
+import weakref
from tornado import ioloop
from tornado.log import gen_log
@@ -85,6 +86,11 @@
signal = None
+_watched_files = set()
+_reload_hooks = []
+_reload_attempted = False
+_io_loops = weakref.WeakKeyDictionary()
+
def start(io_loop=None, check_time=500):
"""Restarts the process automatically when a module is modified.
@@ -92,6 +98,11 @@ def start(io_loop=None, check_time=500):
so will terminate any pending requests.
"""
io_loop = io_loop or ioloop.IOLoop.instance()
+ if io_loop in _io_loops:
+ return
+ _io_loops[io_loop] = True
+ if len(_io_loops) > 1:
+ gen_log.warning("tornado.autoreload started more than once in the same process")
add_reload_hook(functools.partial(_close_all_fds, io_loop))
modify_times = {}
callback = functools.partial(_reload_on_update, modify_times)
@@ -110,8 +121,6 @@ def wait():
start(io_loop)
io_loop.start()
-_watched_files = set()
-
def watch(filename):
"""Add a file to the watch list.
@@ -120,8 +129,6 @@ def watch(filename):
"""
_watched_files.add(filename)
-_reload_hooks = []
-
def add_reload_hook(fn):
"""Add a function to be called before reloading the process.
@@ -141,8 +148,6 @@ def _close_all_fds(io_loop):
except Exception:
pass
-_reload_attempted = False
-
def _reload_on_update(modify_times):
if _reload_attempted:
View
4 website/sphinx/releases/next.rst
@@ -141,3 +141,7 @@ In progress
* The ``{% apply %}`` directive now works properly with functions that return
both unicode strings and byte strings (previously only byte strings were
supported).
+* Calling `tornado.autoreload.start` (or creating an `Application` with
+ ``debug=True``) twice on the same `IOLoop` now does nothing (instead of
+ creating multiple periodic callbacks). Starting autoreload on
+ more than one `IOLoop` in the same process now logs a warning.

0 comments on commit 50e0a97

Please sign in to comment.
Something went wrong with that request. Please try again.