当前位置: 首页>>代码示例>>Python>>正文


Python fcntl.LOCK_SH属性代码示例

本文整理汇总了Python中fcntl.LOCK_SH属性的典型用法代码示例。如果您正苦于以下问题:Python fcntl.LOCK_SH属性的具体用法?Python fcntl.LOCK_SH怎么用?Python fcntl.LOCK_SH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在fcntl的用法示例。


在下文中一共展示了fcntl.LOCK_SH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wait

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def wait(self, wait_pb, *args):
        log.info(" ".join(args))
        container_id = wait_pb.container_id.value
        state = deimos.state.State(self.state_root, mesos_id=container_id)
        self.state = state
        deimos.sig.install(self.stop_docker_and_resume)
        state.await_launch()
        try:  # Wait for the observe lock so observe completes first
            state.lock("observe", LOCK_SH, seconds=None)
            state.lock("wait", LOCK_SH, seconds=None)
        except IOError as e:                       # Allows for signal recovery
            if e.errno != errno.EINTR:
                raise e
            state.lock("observe", LOCK_SH, seconds=1)
            state.lock("wait", LOCK_SH, seconds=1)
        termination = (state.exit() if state.exit() is not None else 64) << 8
        recordio.write(Termination,
                       killed=False,
                       message="",
                       status=termination)
        if state.exit() is not None:
            return state.exit()
        raise Err("Wait lock is not held nor is exit file present") 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:25,代码来源:docker.py

示例2: containers

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def containers(self, *args):
        log.info(" ".join(args))
        data = Run(data=True)(deimos.docker.docker("ps", "--no-trunc", "-q"))
        mesos_ids = []
        for line in data.splitlines():
            cid = line.strip()
            state = deimos.state.State(self.state_root, docker_id=cid)
            if not state.exists():
                continue
            try:
                state.lock("wait", LOCK_SH | LOCK_NB)
            except deimos.flock.Err:     # LOCK_EX held, so launch() is running
                mesos_ids += [state.mesos_container_id()]
        containers = Containers()
        for mesos_id in mesos_ids:
            container = containers.containers.add()
            container.value = mesos_id
        recordio.writeProto(containers)
        return 0 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:21,代码来源:docker.py

示例3: AcquireFileLock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def AcquireFileLock(target_file, flags):
  """ Lock the target file. Note that if |target_file| is closed, the lock is
    automatically released.
  Args:
    target_file: file handle of the file to acquire lock.
    flags: can be any of the type LOCK_EX, LOCK_SH, LOCK_NB, or a bitwise
      OR combination of flags.
  """
  assert flags in (
      LOCK_EX, LOCK_SH, LOCK_NB, LOCK_EX | LOCK_NB, LOCK_SH | LOCK_NB)
  if os.name == 'nt':
    _LockImplWin(target_file, flags)
  elif os.name == 'posix':
    _LockImplPosix(target_file, flags)
  else:
    raise NotImplementedError('%s is not supported' % os.name) 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:18,代码来源:lock.py

示例4: _shareLock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _shareLock(db):
    """
    Take a share lock on the database syslock when an optional migration might
    run. If it conflicts due to an ongoing update then bail out.
    """
    if db.database == ':memory:':
        # Nothing to lock
        return None, True
    lockPath = os.path.join(os.path.dirname(db.database), 'syslock')
    try:
        lockFile = open(lockPath, 'r+')
        fcntl.lockf(lockFile.fileno(), fcntl.LOCK_SH | fcntl.LOCK_NB)
    except IOError as err:
        if err.args[0] in (errno.EAGAIN, errno.EACCES, errno.EROFS):
            # Busy or no write access; skip optional migrations
            return None, False
        elif err.args[0] == errno.ENOENT:
            # Database has never been locked. Probably running in a testsuite,
            # so proceed anyway.
            return None, True
        raise
    return lockFile, True 
开发者ID:sassoftware,项目名称:conary,代码行数:24,代码来源:schema.py

示例5: can_obtain_lock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def can_obtain_lock(basename):
    """
    We temporarily obtain a shared, nonblocking lock to a lockfile to determine
    whether the associated process is currently running. Returns True if it is
    safe to continue execution (no lock conflict), False if not.

    `basename` is the basename of a lockfile situated in the LOCK_DIRECTORY.
    """
    lock_file = os.path.join(LOCK_DIRECTORY, basename)
    try:
        lh = open(lock_file, "r")
    except FileNotFoundError:  # noqa: F821
        # Process may not have run during this session, safe to continue
        return True

    try:
        # Obtain a nonblocking, shared lock
        fcntl.lockf(lh, fcntl.LOCK_SH | fcntl.LOCK_NB)
    except IOError:
        sdlog.error(LOCK_ERROR.format(lock_file))
        return False

    return True 
开发者ID:freedomofpress,项目名称:securedrop-workstation,代码行数:25,代码来源:Util.py

示例6: get_kernel_header

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def get_kernel_header(self, name='kernel'):
        """
        Generate and store kernel.h

        :return: tuple of filename of header and file pointer of lockfile
        """
        file_name = 'kernel.h'
        file_path = self.get_intermediate_location(
            file_name, machine_and_compiler_dependent=False)
        lock_mode, lock_fp = self.lock_intermediate(file_path)
        if lock_mode == fcntl.LOCK_SH:
            # use cache
            with open(file_path) as f:
                code = f.read()
        else:  # lock_mode == fcntl.LOCK_EX
            # needs update
            func_decl = self._build_kernel_function_declaration(name=name)
            scalar_decls = self.get_scalar_declarations()
            code = CGenerator().visit(
                c_ast.FileAST(ext=[func_decl]+scalar_decls))
            with open(file_path, 'w') as f:
                f.write(code)
            fcntl.flock(lock_fp, fcntl.LOCK_SH)  # degrade to shared lock

        return file_name, lock_fp 
开发者ID:RRZE-HPC,项目名称:kerncraft,代码行数:27,代码来源:kernel.py

示例7: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def __init__(self, kernel, machine, cores=1, symbolic=False):
        """Initialize layer condition based predictor from kernel and machine object."""
        CachePredictor.__init__(self, kernel, machine, cores=cores)
        if isinstance(kernel, KernelCode):
            # Make use of caching for symbolic LC representation:
            file_name = 'LC_analysis.pickle.lzma'
            file_path = kernel.get_intermediate_location(
                file_name, machine_and_compiler_dependent=False, other_dependencies=[str(cores)])
            lock_mode, lock_fp = kernel.lock_intermediate(file_path)
            if lock_mode == fcntl.LOCK_SH:
                # use cache
                self.results = compress_pickle.load(file_path)
                lock_fp.close()  # release lock
            else:  # lock_mode == fcntl.LOCK_EX
                # needs update
                self.build_symbolic_LCs()
                compress_pickle.dump(self.results, file_path)
                lock_fp.close()  # release lock
        else:
            # No caching support without filename for kernel code
            self.build_symbolic_LCs()

        if not symbolic:
            self.desymbolize() 
开发者ID:RRZE-HPC,项目名称:kerncraft,代码行数:26,代码来源:cacheprediction.py

示例8: read_acquire

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def read_acquire(self, timeout = None):
		return self.__acquire("r", LOCK_SH, timeout) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:4,代码来源:RWLock.py

示例9: _lock_file_posix

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _lock_file_posix(self, path, exclusive=True):
        lock_path = path + '.lock'
        if exclusive is True:
            f_lock = open(lock_path, 'w')
            fcntl.lockf(f_lock, fcntl.LOCK_EX)
        else:
            f_lock = open(lock_path, 'r')
            fcntl.lockf(f_lock, fcntl.LOCK_SH)
        if os.path.exists(lock_path) is False:
            f_lock.close()
            return None
        return f_lock 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:14,代码来源:cache.py

示例10: observe

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def observe(self, *args):
        log.info(" ".join(args))
        state = deimos.state.State(self.state_root, mesos_id=args[0])
        self.state = state
        deimos.sig.install(self.stop_docker_and_resume)
        state.await_launch()
        try:  # Take the wait lock to block calls to wait()
            state.lock("wait", LOCK_SH, seconds=None)
        except IOError as e:                       # Allows for signal recovery
            if e.errno != errno.EINTR:
                raise e
            state.lock("wait", LOCK_SH, seconds=1)
        if state.exit() is not None:
            return state.exit()
        raise Err("Wait lock is not held nor is exit file present") 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:17,代码来源:docker.py

示例11: format_lock_flags

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def format_lock_flags(flags):
    tokens = [("EX", fcntl.LOCK_EX), ("SH", fcntl.LOCK_SH),
               ("UN", fcntl.LOCK_UN), ("NB", fcntl.LOCK_NB)]
    return "|".join(s for s, flag in tokens if (flags & flag) != 0) 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:6,代码来源:flock.py

示例12: await_launch

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def await_launch(self):
        lk_l = self.lock("launch", LOCK_SH)
        self.ids(3)
        if self.cid() is None:
            lk_l.unlock()
            self.await_cid()
            lk_l = self.lock("launch", LOCK_SH)
        return lk_l 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:10,代码来源:state.py

示例13: get_rpc_port_by_rank

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def get_rpc_port_by_rank(self, rank, num_servers):
        if self.mpirun_proc is None:
            raise RuntimeError("Launch mpirun_proc before reading of rpc ports")

        if self._rpc_ports is not None:
            return self._rpc_ports[rank]

        server_info_pattern = re.compile("^" + LINE_TOKEN +
                                         ":([\d]+):([\d]+):([\d]+):" +
                                         LINE_TOKEN + "$")
        self._tmpfile.seek(0)
        while True:
            fcntl.lockf(self._tmpfile, fcntl.LOCK_SH)
            line_count = sum(1 for line in self._tmpfile if server_info_pattern.match(line))
            self._tmpfile.seek(0)
            fcntl.lockf(self._tmpfile, fcntl.LOCK_UN)

            if line_count == num_servers:
                break
            else:
                time.sleep(0.1)

        server_infos = [tuple([int(server_info_pattern.match(line).group(1)),
                               int(server_info_pattern.match(line).group(3))])
                        for line in self._tmpfile]
        server_infos = sorted(server_infos, key=lambda x: x[0])
        self._rpc_ports = [row[1] for row in server_infos]
        logger.debug("get_rpc_ports: ports (in MPI rank order): %s", self._rpc_ports)
        self._tmpfile.close()
        return self._rpc_ports[rank] 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:32,代码来源:mpilauncher.py

示例14: lock_shared

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def lock_shared(self, length=0, start=0, whence=0, nb=0):
        if nb:
            flag = fcntl.LOCK_SH | fcntl.LOCK_NB
        else:
            flag = fcntl.LOCK_SH
        self._lock(flag, length, start, whence) 
开发者ID:kdart,项目名称:pycopia,代码行数:8,代码来源:UserFile.py

示例15: flock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def flock(lockfile: Union[int, IO[Any]], shared: bool=False) -> Iterator[None]:
    """Lock a file object using flock(2) for the duration of a 'with' statement.

       If shared is True, use a LOCK_SH lock, otherwise LOCK_EX."""

    fcntl.flock(lockfile, fcntl.LOCK_SH if shared else fcntl.LOCK_EX)
    try:
        yield
    finally:
        fcntl.flock(lockfile, fcntl.LOCK_UN) 
开发者ID:zulip,项目名称:zulip,代码行数:12,代码来源:context_managers.py


注:本文中的fcntl.LOCK_SH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。