diff --git a/magicbus/plugins/opsys.py b/magicbus/plugins/opsys.py index d2fd5ad2..b39566e8 100644 --- a/magicbus/plugins/opsys.py +++ b/magicbus/plugins/opsys.py @@ -261,8 +261,16 @@ def wait(self, timeout=None, poll_interval=0.1): def join(self, timeout=None, poll_interval=0.1): """Return when the PID file does not exist, or the timeout expires.""" + try: + initial_stat = os.stat(self.pidfile) + except OSError: # file does not exist + return + starttime = time.time() while timeout is None or time.time() - starttime <= timeout: - if not os.path.exists(self.pidfile): - return + try: + if initial_stat != os.stat(self.pidfile): + return # file has been changed/replaced + except OSError: + return # file does not exist time.sleep(poll_interval) diff --git a/magicbus/test/test_signals.py b/magicbus/test/test_signals.py index dcde1f5d..4b87a7eb 100644 --- a/magicbus/test/test_signals.py +++ b/magicbus/test/test_signals.py @@ -56,6 +56,7 @@ def test_SIGHUP_daemonized(self): kill(pid, SIGHUP) # Give the server some time to restart + pidfile.join() time.sleep(1) new_pid = pidfile.wait(5) assertNotEqual(new_pid, None)