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