def _clean_prior(self): """ Cleans up from a previous task that didn't exit cleanly. Returns ``True`` if previous task was cleaned. """ if self._loaded: try: pid_file = daemon.get_daemon_pidfile(self) # check if it exists so we don't raise if os.path.isfile(pid_file): # read pid from file pid = int(common.readfile(pid_file)) # check if pid file is stale if pid and not daemon.pid_exists(pid): common.safe_remove_file(pid_file) raise ValueError except (ValueError, TypeError): self._clean() return True return False
def test__pid_exists(self): """ daemon.pid_exists: determines if process exists for pid. """ self.assertTrue(daemon.pid_exists(1)) # valid.. let's assume 1 exists self.assertFalse(daemon.pid_exists(99999999)) # invalid