From e23db1e48e17f184e18b85dd62c1ea210affd94f Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 11 Mar 2019 11:24:59 -0500 Subject: [PATCH] handle a crash via broken pipe --- CHANGES.rst | 7 +++++++ src/hupper/reloader.py | 24 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3246cc4..4df2ca1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +unreleased +========== + +- If the worker crashes immediately, sometimes ``hupper`` would go into a + restart loop instead of waiting for a code change. + See https://github.com/Pylons/hupper/pull/50 + 1.6 (2019-03-06) ================ diff --git a/src/hupper/reloader.py b/src/hupper/reloader.py index 8f3de6f..16a0502 100644 --- a/src/hupper/reloader.py +++ b/src/hupper/reloader.py @@ -162,10 +162,26 @@ def _run_worker(self): continue if cmd is None: - self.logger.info( - 'Broken pipe to server, triggering a reload.' - ) - force_restart = True + if worker.is_alive(): + # the worker socket has died but the process is still + # alive (somehow) so wait a brief period to see if it + # dies on its own - if it does die then we want to + # treat it as a crash and wait for changes before + # reloading, if it doesn't die then we want to force + # reload the app immediately because it probably + # didn't die due to some file changes + time.sleep(self.reload_interval) + + if worker.is_alive(): + self.logger.info( + 'Broken pipe to server, triggering a reload.' + ) + force_restart = True + + else: + self.logger.debug( + 'Broken pipe to server, looks like a crash.' + ) break if cmd[0] == 'reload':