tornado: Fix bugs in Tornado autoreload library.

This fixes two issues:

* The syntax check logic we had for zerver.tornado.autoreload would
  end up clearing _reload_hooks if one of the files that had changed
  was zerver.tornado.autoreload itself (because we'd had re-imported
  the current module), which could be incredibly confusing when trying
  to test the autoreload logic.  It seems better to just not run the
  syntax check for syntax errors in this file.

  Similarly, because reloading event_queue.py would destroy the state
  in the queues, we avoid that as well.

* We make sure to flush stdout after running and reload hooks, to make
  sure their output reaches the user.
This commit is contained in:
Tim Abbott
2019-08-02 12:17:36 -07:00
parent a43b2f7a43
commit 8be3df0e29

View File

@@ -180,6 +180,13 @@ def _check_file(modify_times, module, path):
else:
return
if path == __file__ or path == os.path.join(os.path.dirname(__file__),
"event_queue.py"):
# Assume that the autoreload library itself imports correctly,
# because reloading this file will destroy its state,
# including _reload_hooks
return True
try:
importlib.reload(module)
except Exception:
@@ -193,6 +200,8 @@ def _reload():
_reload_attempted = True
for fn in _reload_hooks:
fn()
# Make sure any output from reload hooks makes it to stdout.
sys.stdout.flush()
if hasattr(signal, "setitimer"):
# Clear the alarm signal set by
# ioloop.set_blocking_log_threshold so it doesn't fire