diff --git a/magicbus/plugins/opsys.py b/magicbus/plugins/opsys.py index 4be4ff3c..7a1c8335 100644 --- a/magicbus/plugins/opsys.py +++ b/magicbus/plugins/opsys.py @@ -265,8 +265,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 45e54a5d..f9f9f619 100644 --- a/magicbus/test/test_signals.py +++ b/magicbus/test/test_signals.py @@ -57,6 +57,7 @@ def test_SIGHUP_daemonized(self): kill(pid, SIGHUP) # Give the server some time to restart + pidfile.join() time.sleep(1) for _ in range(6): new_pid = pidfile.wait(5)