예제 #1
0
파일: task.py 프로젝트: nyimbi/focus
    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
예제 #2
0
파일: task.py 프로젝트: xtrementl/focus
    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
예제 #3
0
 def test__get_daemon_pidfile(self):
     """ daemon.get_daemon_pidfile: returns correct pid file for task.
         """
     task = MockTask()
     filename = os.path.join(task.base_dir, ".focusd.pid")
     self.assertEqual(daemon.get_daemon_pidfile(task), filename)