'Validate pidfile and make it stale if needed'

def validate(self):

    if (not self.fname):
        return
    try:
        with open(self.fname, 'r') as f:
            try:
                wpid = int(f.read())
            except ValueError:
                return
            try:
                os.kill(wpid, 0)
                return wpid
            except OSError as e:
                if (e.args[0] == errno.EPERM):
                    return wpid
                if (e.args[0] == errno.ESRCH):
                    return
                raise
    except IOError as e:
        if (e.args[0] == errno.ENOENT):
            return
        raise
