From d894c3484ee6a6e805982cd6dc841aadafebcc10 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 27 Oct 2025 16:09:53 -0700 Subject: [PATCH] Remove obsolete wsgi_restart configuration option I believe this was used at some point to automatically restart the development server when the LNT sources were changed. However, this configuration option doesn't appear to be hooked up anywhere, so this is effectively dead code. Furthermore, Werzeug supports the `use_reloader=True` argument that could be used when we start a development server if we wanted this functionality (which we don't need at the moment). --- lnt/lnttool/create.py | 4 - lnt/util/wsgi_restart.py | 123 ------------------ tests/SharedInputs/SmallInstance/lnt.cfg | 4 - .../Inputs/rerun_server_instance/lnt.cfg | 4 - .../Inputs/lnt_v0.4.0_basic_instance/lnt.cfg | 4 - .../Inputs/lnt_v0.4.0_filled_instance/lnt.cfg | 4 - 6 files changed, 143 deletions(-) delete mode 100644 lnt/util/wsgi_restart.py diff --git a/lnt/lnttool/create.py b/lnt/lnttool/create.py index 7b768dbe..983fceb7 100644 --- a/lnt/lnttool/create.py +++ b/lnt/lnttool/create.py @@ -58,10 +58,6 @@ # reports to different email address. 'to' : [(".*", None)], } - -# Enable automatic restart using the wsgi_restart module; this should be off in -# a production environment. -wsgi_restart = False """ kWSGITemplate = """\ diff --git a/lnt/util/wsgi_restart.py b/lnt/util/wsgi_restart.py deleted file mode 100644 index 927cc0f3..00000000 --- a/lnt/util/wsgi_restart.py +++ /dev/null @@ -1,123 +0,0 @@ -# This code lifted from the mod_wsgi docs. -import os -from pathlib import Path -from typing import Sequence -import sys -import signal -import threading -import atexit -import queue - -_interval = 1.0 -_times = {} -_files: Sequence[Path] = [] - -_running = False -_queue: queue.Queue = queue.Queue() -_lock = threading.Lock() - - -def _restart(path): - _queue.put(True) - prefix = 'monitor (pid=%d):' % os.getpid() - print('%s Change detected to \'%s\'.' % (prefix, path), file=sys.stderr) - print('%s Triggering process restart.' % prefix, file=sys.stderr) - os.kill(os.getpid(), signal.SIGINT) - - -def _modified(path): - try: - # If path doesn't denote a file and were previously - # tracking it, then it has been removed or the file type - # has changed so force a restart. If not previously - # tracking the file then we can ignore it as probably - # pseudo reference such as when file extracted from a - # collection of modules contained in a zip file. - - if not os.path.isfile(path): - return path in _times - - # Check for when file last modified. - - mtime = os.stat(path).st_mtime - if path not in _times: - _times[path] = mtime - - # Force restart when modification time has changed, even - # if time now older, as that could indicate older file - # has been restored. - - if mtime != _times[path]: - return True - except Exception: - # If any exception occured, likely that file has been - # been removed just before stat(), so force a restart. - - return True - - return False - - -def _monitor(): - while True: - # Check modification times on all files in sys.modules. - - for module in sys.modules.values(): - if not hasattr(module, '__file__'): - continue - path = getattr(module, '__file__') - if not path: - continue - if os.path.splitext(path)[1] in ['.pyc', '.pyo', '.pyd']: - path = path[:-1] - - if _modified(path): - return _restart(path) - - # Check modification times on files which have - # specifically been registered for monitoring. - - for path in _files: - if _modified(path): - return _restart(path) - - # Go to sleep for specified interval. - - try: - return _queue.get(timeout=_interval) - except Exception: - pass - - -_thread = threading.Thread(target=_monitor) -_thread.setDaemon(True) - - -def _exiting(): - try: - _queue.put(True) - except Exception: - pass - _thread.join() - - -atexit.register(_exiting) - - -def track(path): - if path not in _files: - _files.append(path) - - -def start(interval=1.0): - global _interval - if interval < _interval: - _interval = interval - - global _running - _lock.acquire() - if not _running: - prefix = 'monitor (pid=%d):' % os.getpid() - print('%s Starting change monitor.' % prefix, file=sys.stderr) - _running = True - _thread.start() diff --git a/tests/SharedInputs/SmallInstance/lnt.cfg b/tests/SharedInputs/SmallInstance/lnt.cfg index 57fb9fdf..77736c22 100644 --- a/tests/SharedInputs/SmallInstance/lnt.cfg +++ b/tests/SharedInputs/SmallInstance/lnt.cfg @@ -50,7 +50,3 @@ nt_emailer = { # reports to different email address. 'to' : [(".*", None)], } - -# Enable automatic restart using the wsgi_restart module; this should be off in -# a production environment. -wsgi_restart = False diff --git a/tests/runtest/Inputs/rerun_server_instance/lnt.cfg b/tests/runtest/Inputs/rerun_server_instance/lnt.cfg index 7a1967c4..95273469 100644 --- a/tests/runtest/Inputs/rerun_server_instance/lnt.cfg +++ b/tests/runtest/Inputs/rerun_server_instance/lnt.cfg @@ -46,7 +46,3 @@ nt_emailer = { # reports to different email address. 'to' : [(".*", None)], } - -# Enable automatic restart using the wsgi_restart module; this should be off in -# a production environment. -wsgi_restart = False diff --git a/tests/server/db/Inputs/lnt_v0.4.0_basic_instance/lnt.cfg b/tests/server/db/Inputs/lnt_v0.4.0_basic_instance/lnt.cfg index ba43b5ac..86e736f4 100644 --- a/tests/server/db/Inputs/lnt_v0.4.0_basic_instance/lnt.cfg +++ b/tests/server/db/Inputs/lnt_v0.4.0_basic_instance/lnt.cfg @@ -47,8 +47,4 @@ nt_emailer = { 'to' : [(".*", None)], } -# Enable automatic restart using the wsgi_restart module; this should be off in -# a production environment. -wsgi_restart = False - blacklist = 'blacklist' diff --git a/tests/server/db/Inputs/lnt_v0.4.0_filled_instance/lnt.cfg b/tests/server/db/Inputs/lnt_v0.4.0_filled_instance/lnt.cfg index 3bfb7347..3a736f3d 100644 --- a/tests/server/db/Inputs/lnt_v0.4.0_filled_instance/lnt.cfg +++ b/tests/server/db/Inputs/lnt_v0.4.0_filled_instance/lnt.cfg @@ -46,7 +46,3 @@ nt_emailer = { # reports to different email address. 'to' : [(".*", None)], } - -# Enable automatic restart using the wsgi_restart module; this should be off in -# a production environment. -wsgi_restart = False