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 330d39cd..a4653c26 100644 --- a/magicbus/test/test_signals.py +++ b/magicbus/test/test_signals.py @@ -55,6 +55,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) assert new_pid is not None