Python msvcrt 模块,LK_NBLCK 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用msvcrt.LK_NBLCK

项目:porcupine    作者:Akuli    | 项目源码 | 文件源码
def _lock(fileno):
    """Try to lock a file. Return True on success."""
    # closing the file unlocks it, so we don't need to unlock here
    if platform.system() == 'Windows':
        try:
            msvcrt.locking(fileno, msvcrt.LK_NBLCK, 10)
            return True
        except PermissionError:
            return False
    else:
        try:
            fcntl.lockf(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB)
            return True
        # the docs recommend catching both of these
        except (BlockingIOError, PermissionError):
            return False
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def trylock(self):
        msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
项目:deb-python-fasteners    作者:openstack    | 项目源码 | 文件源码
def _trylock(lockfile):
        fileno = lockfile.fileno()
        msvcrt.locking(fileno, msvcrt.LK_NBLCK, 1)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def lock(self, no_wait=False):
        import msvcrt
        if no_wait:
            op = msvcrt.LK_NBLCK
        else:
            op = msvcrt.LK_LOCK

        self.fd.seek(0)
        msvcrt.locking(self.fd, op, 1)
项目:bksync    作者:oddy    | 项目源码 | 文件源码
def trylock(self):
        if self.lockfile is None or self.lockfile.closed:
            self.lockfile = open(self.path, 'a')
        try:
            if os.name == 'nt':
                msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
            else:
                fcntl.lockf(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
            return True
        except IOError,e:
            if e.errno in (errno.EACCES, errno.EAGAIN):
                return False
            raise
项目:autosub-bootstrapbill    作者:BenjV    | 项目源码 | 文件源码
def _lock_file(self):
        # Lock just the first byte
        try:
            msvcrt.locking(self.fp.fileno(), msvcrt.LK_NBLCK, 1)
        except IOError:
            raise LockError(self.fp.name)
项目:GAMADV-X    作者:taers232c    | 项目源码 | 文件源码
def trylock(self):
        msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def _lock_file(self):
        # Lock just the first byte
        try:
            msvcrt.locking(self.fp.fileno(), msvcrt.LK_NBLCK, 1)
        except IOError:
            raise LockError(self.fp.name)
项目:LIS-Tempest    作者:LIS    | 项目源码 | 文件源码
def trylock(self):
        msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)