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


Python msvcrt.LK_NBLCK属性代码示例

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


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

示例1: _acquire

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _acquire(self):
        open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC

        try:
            fd = os.open(self._lock_file, open_mode)
        except OSError:
            pass
        else:
            try:
                msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
            except (IOError, OSError):
                try:
                    os.close(fd)
                except: 
                    fd.close()
            else:
                self._lock_file_fd = fd
        return None 
开发者ID:tvaddonsco,项目名称:plugin.git.browser,代码行数:20,代码来源:filelock.py

示例2: _lock_file

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _lock_file(file, block):
            # Lock just the first byte of the file
            retry = True
            while retry:
                retry = False
                try:
                    msvcrt.locking(
                        file.fileno(), msvcrt.LK_LOCK if block else msvcrt.LK_NBLCK, 1
                    )
                except OSError as e:
                    if block and e.errno == 36:
                        # Windows says 'resource deadlock avoided', but we truly want
                        # a longer blocking wait: try again
                        retry = True
                    else:
                        raise LockError(
                            "Couldn't lock {0}, errno is {1}".format(file.name, e.errno)
                        ) 
开发者ID:mideind,项目名称:ReynirPackage,代码行数:20,代码来源:glock.py

示例3: _acquire

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _acquire(self):
        open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC

        try:
            fd = os.open(self._lock_file, open_mode)
        except OSError:
            pass
        else:
            try:
                msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
            except (IOError, OSError):
                os.close(fd)
            else:
                self._lock_file_fd = fd
        return None 
开发者ID:a4k-openproject,项目名称:a4kScrapers,代码行数:17,代码来源:filelock.py

示例4: _trylock

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _trylock(lockfile):
        fileno = lockfile.fileno()
        msvcrt.locking(fileno, msvcrt.LK_NBLCK, 1) 
开发者ID:harlowja,项目名称:fasteners,代码行数:5,代码来源:process_lock.py

示例5: lock_exclusive

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def lock_exclusive(self, length, start=0, whence=0, nb=0):
        """Locking method compatible with Posix files."""
        if nb:
            mode = msvcrt.LK_NBLCK
        else:
            mode = msvcrt.LK_LOCK
        orig = self.tell()
        self.seek(start, whence)
        try:
            msvcrt.locking(self.fileno(), mode, length)
        finally:
            self.seek(orig) 
开发者ID:kdart,项目名称:pycopia,代码行数:14,代码来源:WindowsServer.py

示例6: acquire

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def acquire(self, blocking):
        if not self._lock.acquire(blocking):
            return False
        while True:
            try:
                fd = os.open(self._lock_path, OPEN_MODE)
                msvcrt.locking(fd, msvcrt.LK_LOCK if blocking else msvcrt.LK_NBLCK, 1)
                self._fd = fd
                return True
            except OSError:
                if not blocking:
                    self._lock.release()
                    return False 
开发者ID:iamdefinitelyahuman,项目名称:py-solc-x,代码行数:15,代码来源:lock.py

示例7: _locked

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _locked(
            fileno: int,
            blocked_cb: Callable[[], None],
    ) -> Generator[None, None, None]:
        try:
            # TODO: https://github.com/python/typeshed/pull/3607
            msvcrt.locking(fileno, msvcrt.LK_NBLCK, _region)  # type: ignore
        except OSError:
            blocked_cb()
            while True:
                try:
                    # TODO: https://github.com/python/typeshed/pull/3607
                    msvcrt.locking(fileno, msvcrt.LK_LOCK, _region)  # type: ignore  # noqa: E501
                except OSError as e:
                    # Locking violation. Returned when the _LK_LOCK or _LK_RLCK
                    # flag is specified and the file cannot be locked after 10
                    # attempts.
                    if e.errno != errno.EDEADLOCK:
                        raise
                else:
                    break

        try:
            yield
        finally:
            # From cursory testing, it seems to get unlocked when the file is
            # closed so this may not be necessary.
            # The documentation however states:
            # "Regions should be locked only briefly and should be unlocked
            # before closing a file or exiting the program."
            # TODO: https://github.com/python/typeshed/pull/3607
            msvcrt.locking(fileno, msvcrt.LK_UNLCK, _region)  # type: ignore 
开发者ID:pre-commit,项目名称:pre-commit,代码行数:34,代码来源:file_lock.py

示例8: _lock_file

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
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) 
开发者ID:naparuba,项目名称:opsbro,代码行数:8,代码来源:lockfile.py

示例9: lock_file

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def lock_file(handle):
    if sys.platform == 'win32':
        msvcrt.locking(handle.fileno(), msvcrt.LK_NBLCK, 1)
    else:
        fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB) 
开发者ID:openstack,项目名称:oslo.concurrency,代码行数:7,代码来源:test_lockutils.py

示例10: _lock_file

# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import LK_NBLCK [as 别名]
def _lock_file(file):
            # Lock just the first byte
            try:
                msvcrt.locking(file.fileno(), msvcrt.LK_NBLCK, 1)
            except IOError:
                raise LockError("Couldn't lock %r" % file.name) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:8,代码来源:__init__.py


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