Skip to content

Commit

Permalink
Merge pull request #88 from Pylons/graceful-shutdown
Browse files Browse the repository at this point in the history
support triggering a graceful shutdown from within the worker process
  • Loading branch information
mmerickel committed Jan 26, 2024
2 parents 79c43b9 + 3749097 commit 6f69a98
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -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)
===================
Expand Down
4 changes: 4 additions & 0 deletions src/hupper/interfaces.py
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/hupper/reloader.py
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/hupper/worker.py
Expand Up @@ -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):
Expand Down

0 comments on commit 6f69a98

Please sign in to comment.