diff --git a/CHANGES.rst b/CHANGES.rst index b5e4e04..d24cdb2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,10 @@ unreleased - Fix issues with watchman when the server shuts down unexpectedly and when subscriptions are canceled. +- Add ``hupper.get_reloader().graceful_shutdown()`` which can be used within + your own app to trigger a full shutdown of the worker as well as the + monitoring. + 1.12.1 (2023-08-27) =================== diff --git a/src/hupper/interfaces.py b/src/hupper/interfaces.py index 7803ea0..1edf760 100644 --- a/src/hupper/interfaces.py +++ b/src/hupper/interfaces.py @@ -10,6 +10,10 @@ def watch_files(self, files): def trigger_reload(self): """Signal the monitor to execute a reload.""" + @abstractmethod + def graceful_shutdown(self): + """Signal the monitor to gracefully shutdown.""" + class IFileMonitorFactory(ABC): @abstractmethod diff --git a/src/hupper/reloader.py b/src/hupper/reloader.py index 1d27013..7ab8500 100644 --- a/src/hupper/reloader.py +++ b/src/hupper/reloader.py @@ -316,6 +316,9 @@ def handle_packet(packet): for path in cmd[1]: self.monitor.add_path(path) + elif cmd[0] == 'graceful_shutdown': + os.write(self.control_w, ControlSignal.SIGTERM) + else: # pragma: no cover raise RuntimeError('received unknown control signal', cmd) diff --git a/src/hupper/worker.py b/src/hupper/worker.py index 3ce5d11..68cae5b 100644 --- a/src/hupper/worker.py +++ b/src/hupper/worker.py @@ -242,6 +242,9 @@ def watch_files(self, files): def trigger_reload(self): self.pipe.send(('reload',)) + def graceful_shutdown(self): + self.pipe.send(('graceful_shutdown',)) + def watch_control_pipe(pipe): def handle_packet(packet):