Python fcntl.LOCK_UN属性代码示例

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

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

示例1: release

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def release(self):
        """Release the lock by deleting `self.lockfile`."""
        if not self._lock.is_set():
            return False
        try:
            fcntl.lockf(self._lockfile, fcntl.LOCK_UN)
        except IOError:  # pragma: no cover
            pass
        finally:
            self._lock.clear()
            self._lockfile = None
            try:
                os.unlink(self.lockfile)
            except (IOError, OSError):  # pragma: no cover
                pass
            return True 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:20,代码来源:util.py


示例2: __exit__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
      # Flush any buffered data to disk. This is needed to prevent race
      # condition which happens from the moment of releasing file lock
      # till closing the file.
      self._fo.flush()
      try:
        if sys.platform == 'win32':
          self._fo.seek(0)
          msvcrt.locking(self._fo.fileno(), msvcrt.LK_UNLCK, 1)
        else:
          fcntl.flock(self._fo.fileno(), fcntl.LOCK_UN)
      finally:
        self._fo.close()
      return exc_value is None 
开发者ID:google,项目名称:gtest-parallel,代码行数:18,代码来源:gtest_parallel.py


示例3: unlock_file

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_file(self, name):
        f = self.locks.get(name)
        if not f:
            self.log(DEBUG, "unlock_file: %s not locked", name)
            return
        # XXXX does this create a possible race condition?
        if 0:
            try:
                os.unlink(name)
            except:
                pass
        status = fcntl.lockf(f, fcntl.LOCK_UN)
        f.close()
        del self.locks[name]
        return status 
开发者ID:rucio,项目名称:rucio,代码行数:18,代码来源:pcache.py


示例4: udpate_status

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def udpate_status(status_file_path, module_data, module):
	lock_file_path = "{}.lock".format(status_file_path)
	while True:
		status_file_lock = open(lock_file_path, 'r')
		try:
			fcntl.flock(status_file_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
			with open(status_file_path, "r+") as status_file:
				data = json.load(status_file)
				status_file.seek(0)
				data[module].update(module_data)
				json.dump(data, status_file)
			fcntl.flock(status_file_lock, fcntl.LOCK_UN)
			return
		except:
			time.sleep(0.1)
		status_file_lock.close() 
开发者ID:BishopFox,项目名称:IDontSpeakSSL,代码行数:18,代码来源:utils.py


示例5: __exit__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_val, traceback):
        if (exc_type is None and self._data_written):
            os.replace(self._temp_file_path, self._config_file)
            os.chmod(self._config_file, 0o660)
            shutil.chown(self._config_file, user=USER, group=GROUP)
        else:
            self._temp_file.close()
            os.unlink(self._temp_file_path)
            if (self._Log):
                self._Log.error(f'configuration manager exiting with error: {exc_val}')
        # releasing lock for purposes specified in flock(1) man page under -u (unlock)
        fcntl.flock(self._config_lock, fcntl.LOCK_UN)
        self._config_lock.close()
        if (self._Log):
            self._Log.debug(f'file lock released for {self._file_name}')
        if (exc_type is not ValidationError):
            return True
    #will load json data from file, convert it to a python dict, then returned as object 
开发者ID:DOWRIGHTTV,项目名称:dnxfirewall-cmd,代码行数:23,代码来源:dnx_file_operations.py


示例6: do_write

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def do_write(self, obuf):
        my_flock = flock
        try:
            my_flock(self.log, LOCK_EX)
        except IOError as e:
            # Catch ENOTSUP
            if e.args[0] != 45:
                raise e
            my_flock = lambda x, y: None
        try:
            self.log.write(obuf)
            self.log.flush()
        except:
            pass
        my_flock(self.log, LOCK_UN) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:17,代码来源:SipLogger.py


示例7: unlock_and_close

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_and_close(self):
      """Close and unlock the file using the fcntl.lockf primitive."""
      if self._locked:
        fcntl.lockf(self._fh.fileno(), fcntl.LOCK_UN)
      self._locked = False
      if self._fh:
        self._fh.close() 
开发者ID:mortcanty,项目名称:earthengine,代码行数:9,代码来源:locked_file.py


示例8: release

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def release(self):
        fcntl.flock(self.handle, fcntl.LOCK_UN) 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:4,代码来源:Config.py


示例9: __exit__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
        if self._lock_file:
            fcntl.lockf(self._lock_file.fileno(), fcntl.LOCK_UN)
            self._lock_file.close() 
开发者ID:PrivacyScore,项目名称:PrivacyScore,代码行数:6,代码来源:utils.py


示例10: lock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def lock():
    # Since Local Mode uses the same port for serving, we need a lock in order
    # to allow concurrent test execution.
    local_mode_lock_fd = open(LOCK_PATH, 'w')
    local_mode_lock = local_mode_lock_fd.fileno()
    fcntl.lockf(local_mode_lock, fcntl.LOCK_EX)
    try:
        yield
    finally:
        time.sleep(5)
        fcntl.lockf(local_mode_lock, fcntl.LOCK_UN) 
开发者ID:aws,项目名称:sagemaker-pytorch-training-toolkit,代码行数:15,代码来源:local_mode_utils.py


示例11: unlock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock(f):
            ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
            return (ret == 0) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:locks.py


示例12: _unlock_file

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _unlock_file(f):
    """Unlock file f using lockf and dot locking."""
    if fcntl:
        fcntl.lockf(f, fcntl.LOCK_UN)
    if os.path.exists(f.name + '.lock'):
        os.remove(f.name + '.lock') 
开发者ID:glmcdona,项目名称:meddle,代码行数:8,代码来源:mailbox.py


示例13: _release

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _release(self):
        # Do not remove the lockfile:
        #
        #   https://github.com/benediktschmitt/py-filelock/issues/31
        #   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
        fd = self._lock_file_fd
        self._lock_file_fd = None
        fcntl.flock(fd, fcntl.LOCK_UN)
        os.close(fd)
        return None
# Soft lock
# ~~~~~~~~~ 
开发者ID:a4k-openproject,项目名称:a4kScrapers,代码行数:15,代码来源:filelock.py


示例14: read_release

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def read_release(self):
		with self.__local.f as f:
			self.__local.f = None
			lockf(f, LOCK_UN) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:6,代码来源:RWLock.py


示例15: unlock_file

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock_file(lockfile):
    fcntl.lockf(lockfile, fcntl.LOCK_UN)
    lockfile.close()
# Utility functions for dealing with external processes 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:8,代码来源:utils_misc.py


示例16: unlock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def unlock(self):
        if not self.handle.closed:
            fcntl.flock(self.handle, fcntl.LOCK_UN)
            self.handle.close() 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:6,代码来源:flock.py


示例17: format_lock_flags

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [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


示例18: _write

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _write(filename, contents):
        ''' Actually write the file contents to disk. This helps with mocking. '''
        tmp_filename = filename + '.yedit'
        with open(tmp_filename, 'w') as yfd:
            fcntl.flock(yfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            yfd.write(contents)
            fcntl.flock(yfd, fcntl.LOCK_UN)
        os.rename(tmp_filename, filename) 
开发者ID:RedHatOfficial,项目名称:ansible-redhat_openshift_utils,代码行数:13,代码来源:oc_obj.py


示例19: write_server_info

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def write_server_info(filename, port):
    pid = os.getpid()
    rank = MPI.COMM_WORLD.Get_rank()
    server_info = '{}:{}:{}:{}:{}'.format(LINE_TOKEN, rank, pid, port, LINE_TOKEN).strip()
    logger.debug("write_server_info: line %s, filename %s", server_info, filename)
    time.sleep(0.1 * rank)
    with open(filename, "a") as f:
        fcntl.lockf(f, fcntl.LOCK_EX)
        f.write(server_info + '\n')
        f.flush()
        os.fsync(f.fileno())
        fcntl.lockf(f, fcntl.LOCK_UN)
    return server_info 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:16,代码来源:hetr_server.py


示例20: get_rpc_port_by_rank

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [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


示例21: _unlock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def _unlock(lockfile):
        fcntl.lockf(lockfile, fcntl.LOCK_UN) 
开发者ID:harlowja,项目名称:fasteners,代码行数:4,代码来源:process_lock.py


示例22: __exit__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import LOCK_UN [as 别名]
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
        # Flush to make sure all buffered contents are written to file.
        self.file.flush()
        os.fsync(self.file.fileno())
        # Release the lock on the file.
        fcntl.flock(self.file, fcntl.LOCK_UN)
        self.file.close() 
开发者ID:QwantResearch,项目名称:kartotherian_docker,代码行数:9,代码来源:lock.py



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