Python fcntl.LOCK_SH属性代码示例

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

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


示例16: lockfile

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def lockfile(filename: str, shared: bool=False) -> Iterator[None]:
    """Lock a file using flock(2) for the duration of a 'with' statement.
       If shared is True, use a LOCK_SH lock, otherwise LOCK_EX.
       The file is given by name and will be created if it does not exist."""
    with open(filename, 'w') as lock:
        with flock(lock, shared=shared):
            yield 
开发者ID:zulip,项目名称:zulip,代码行数:11,代码来源:context_managers.py


示例17: _lock_file

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _lock_file(f, exclusive):
            fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:4,代码来源:utils.py


示例18: get_gcs_client

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def get_gcs_client(self) -> luigi.contrib.gcs.GCSClient:
        if (not os.path.isfile(self.discover_cache_local_path)):
            with open(self.discover_cache_local_path, "w") as f:
                try:
                    fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
                    params = {"api": "storage", "apiVersion": "v1"}
                    discovery_http = build_http()
                    for discovery_url in (self._DISCOVERY_URI, self._V2_DISCOVERY_URI):
                        requested_url = uritemplate.expand(discovery_url, params)
                        try:
                            content = _retrieve_discovery_doc(
                                requested_url, discovery_http, False
                            )
                        except HttpError as e:
                            if e.resp.status == http_client.NOT_FOUND:
                                continue
                            else:
                                raise e
                        break
                    f.write(content)
                    fcntl.flock(f, fcntl.LOCK_UN)
                except IOError:
                    # try to read
                    pass
        with open(self.discover_cache_local_path, "r") as f:
            fcntl.flock(f, fcntl.LOCK_SH)
            descriptor = f.read()
            fcntl.flock(f, fcntl.LOCK_UN)
            return luigi.contrib.gcs.GCSClient(oauth_credentials=self._load_oauth_credentials(), descriptor=descriptor) 
开发者ID:m3dev,项目名称:gokart,代码行数:33,代码来源:gcs_config.py


示例19: _lock_buildroot

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _lock_buildroot(self, exclusive):
        lock_type = fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH
        if not self._lock_file:
            self._open_lock()
        try:
            fcntl.lockf(self._lock_file.fileno(), lock_type | fcntl.LOCK_NB)
        except IOError:
            raise BuildRootLocked("Build root is locked by another process.") 
开发者ID:rpm-software-management,项目名称:mock,代码行数:10,代码来源:buildroot.py


示例20: _rootCacheLock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _rootCacheLock(self, shared=1):
        lockType = fcntl.LOCK_EX
        if shared:
            lockType = fcntl.LOCK_SH
        try:
            fcntl.lockf(self.rootCacheLock.fileno(), lockType | fcntl.LOCK_NB)
        except IOError:
            self.state.start("Waiting for rootcache lock")
            fcntl.lockf(self.rootCacheLock.fileno(), lockType)
            self.state.finish("Waiting for rootcache lock") 
开发者ID:rpm-software-management,项目名称:mock,代码行数:12,代码来源:root_cache.py


示例21: lock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def lock(self, exclusive, block=False):
        lock_type = fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH
        try:
            fcntl.lockf(self.lock_file.fileno(),
                        lock_type | (0 if block else fcntl.LOCK_NB))
        except IOError as e:
            if e.errno in (errno.EACCES, errno.EAGAIN):
                raise LvmLocked("LVM is locked")
            raise 
开发者ID:rpm-software-management,项目名称:mock,代码行数:11,代码来源:lvm_root.py


示例22: do_acquire_read_lock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def do_acquire_read_lock(self, wait):
        filedescriptor = self._open(os.O_CREAT | os.O_RDONLY)
        if not wait:
            try:
                fcntl.flock(filedescriptor, fcntl.LOCK_SH | fcntl.LOCK_NB)
                return True
            except IOError:
                os.close(filedescriptor)
                self._filedescriptor.remove()
                return False
        else:
            fcntl.flock(filedescriptor, fcntl.LOCK_SH)
            return True 
开发者ID:abdesslem,项目名称:malwareHunter,代码行数:15,代码来源:synchronization.py


示例23: GetStatus

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def GetStatus(self):
    with util.Lock(SANDBOX_MASTER_LOCK_FILE, fcntl.LOCK_SH):
      status = {}
      status['status'] = self._GetMasterStatus()
      status['sandbox'] = []
      try:
        for sandbox_id in xrange(256):
          status['sandbox'].append(self._GetSandboxStatus(sandbox_id))
      except KeyError:
        pass
    return status 
开发者ID:google,项目名称:catnip,代码行数:13,代码来源:sandbox.py


示例24: _GetMasterStatus

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _GetMasterStatus(self):
    if not os.path.exists(SANDBOX_SETUP_FILE):
      return 'shutdown'
    try:
      with util.Lock(
          SANDBOX_HEALTH_CHECK_LOCK_FILE, fcntl.LOCK_SH|fcntl.LOCK_NB):
        with open(SANDBOX_HEALTH_FILE) as f:
          return f.readline().strip()
    except util.LockFailed:
      return 'warmup'
    except IOError:
      return 'warmup' 
开发者ID:google,项目名称:catnip,代码行数:14,代码来源:sandbox.py


示例25: _GetSandboxStatus

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_SH [as 别名]
def _GetSandboxStatus(self, sandbox_id):
    # Throws KeyError when the user does not exist.
    pwd.getpwnam('catnip%d' % sandbox_id)
    try:
      with util.Lock(os.path.join(SANDBOX_LOCK_BASEDIR, '%d' % sandbox_id),
                     fcntl.LOCK_SH|fcntl.LOCK_NB):
        pass
    except util.LockFailed:
      return {'status': 'running'}
    else:
      return {'status': 'ready'} 
开发者ID:google,项目名称:catnip,代码行数:13,代码来源:sandbox.py



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