當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。