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


Python win32con.LOCKFILE_FAIL_IMMEDIATELY属性代码示例

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


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

示例1: open_and_lock

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import LOCKFILE_FAIL_IMMEDIATELY [as 别名]
def open_and_lock(self, timeout, delay):
      """Open the file and lock it.

      Args:
        timeout: float, How long to try to lock for.
        delay: float, How long to wait between retries

      Raises:
        AlreadyLockedException: if the lock is already acquired.
        IOError: if the open fails.
        CredentialsFileSymbolicLinkError if the file is a symbolic link.
      """
      if self._locked:
        raise AlreadyLockedException('File %s is already locked' %
                                     self._filename)
      start_time = time.time()

      validate_file(self._filename)
      try:
        self._fh = open(self._filename, self._mode)
      except IOError as e:
        # If we can't access with _mode, try _fallback_mode and don't lock.
        if e.errno == errno.EACCES:
          self._fh = open(self._filename, self._fallback_mode)
          return

      # We opened in _mode, try to lock the file.
      while True:
        try:
          hfile = win32file._get_osfhandle(self._fh.fileno())
          win32file.LockFileEx(
              hfile,
              (win32con.LOCKFILE_FAIL_IMMEDIATELY|
               win32con.LOCKFILE_EXCLUSIVE_LOCK), 0, -0x10000,
              pywintypes.OVERLAPPED())
          self._locked = True
          return
        except pywintypes.error as e:
          if timeout == 0:
            raise e

          # If the error is not that the file is already in use, raise.
          if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
            raise

          # We could not acquire the lock. Try again.
          if (time.time() - start_time) >= timeout:
            logger.warn('Could not lock %s in %s seconds' % (
                self._filename, timeout))
            if self._fh:
              self._fh.close()
            self._fh = open(self._filename, self._fallback_mode)
            return
          time.sleep(delay) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:56,代码来源:locked_file.py

示例2: open_and_lock

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import LOCKFILE_FAIL_IMMEDIATELY [as 别名]
def open_and_lock(self, timeout, delay):
        """Open the file and lock it.

        Args:
            timeout: float, How long to try to lock for.
            delay: float, How long to wait between retries

        Raises:
            AlreadyLockedException: if the lock is already acquired.
            IOError: if the open fails.
            CredentialsFileSymbolicLinkError: if the file is a symbolic
                                              link.
        """
        if self._locked:
            raise AlreadyLockedException('File %s is already locked' %
                                         self._filename)
        start_time = time.time()

        validate_file(self._filename)
        try:
            self._fh = open(self._filename, self._mode)
        except IOError as e:
            # If we can't access with _mode, try _fallback_mode
            # and don't lock.
            if e.errno == errno.EACCES:
                self._fh = open(self._filename, self._fallback_mode)
                return

        # We opened in _mode, try to lock the file.
        while True:
            try:
                hfile = win32file._get_osfhandle(self._fh.fileno())
                win32file.LockFileEx(
                    hfile,
                    (win32con.LOCKFILE_FAIL_IMMEDIATELY |
                     win32con.LOCKFILE_EXCLUSIVE_LOCK), 0, -0x10000,
                    pywintypes.OVERLAPPED())
                self._locked = True
                return
            except pywintypes.error as e:
                if timeout == 0:
                    raise

                # If the error is not that the file is already
                # in use, raise.
                if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
                    raise

                # We could not acquire the lock. Try again.
                if (time.time() - start_time) >= timeout:
                    logger.warn('Could not lock %s in %s seconds' % (
                        self._filename, timeout))
                    if self._fh:
                        self._fh.close()
                    self._fh = open(self._filename, self._fallback_mode)
                    return
                time.sleep(delay) 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:59,代码来源:_win32_opener.py

示例3: open_and_lock

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import LOCKFILE_FAIL_IMMEDIATELY [as 别名]
def open_and_lock(self, timeout, delay):
        """Open the file and lock it.

        Args:
            timeout: float, How long to try to lock for.
            delay: float, How long to wait between retries

        Raises:
            AlreadyLockedException: if the lock is already acquired.
            IOError: if the open fails.
            CredentialsFileSymbolicLinkError: if the file is a symbolic
                                              link.
        """
        if self._locked:
            raise locked_file.AlreadyLockedException(
                'File {0} is already locked'.format(self._filename))
        start_time = time.time()

        locked_file.validate_file(self._filename)
        try:
            self._fh = open(self._filename, self._mode)
        except IOError as e:
            # If we can't access with _mode, try _fallback_mode
            # and don't lock.
            if e.errno == errno.EACCES:
                self._fh = open(self._filename, self._fallback_mode)
                return

        # We opened in _mode, try to lock the file.
        while True:
            try:
                hfile = win32file._get_osfhandle(self._fh.fileno())
                win32file.LockFileEx(
                    hfile,
                    (win32con.LOCKFILE_FAIL_IMMEDIATELY |
                     win32con.LOCKFILE_EXCLUSIVE_LOCK), 0, -0x10000,
                    pywintypes.OVERLAPPED())
                self._locked = True
                return
            except pywintypes.error as e:
                if timeout == 0:
                    raise

                # If the error is not that the file is already
                # in use, raise.
                if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
                    raise

                # We could not acquire the lock. Try again.
                if (time.time() - start_time) >= timeout:
                    locked_file.logger.warn('Could not lock %s in %s seconds',
                                            self._filename, timeout)
                    if self._fh:
                        self._fh.close()
                    self._fh = open(self._filename, self._fallback_mode)
                    return
                time.sleep(delay) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:59,代码来源:_win32_opener.py

示例4: open_and_lock

# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import LOCKFILE_FAIL_IMMEDIATELY [as 别名]
def open_and_lock(self, timeout, delay):
            """Open the file and lock it.

            Args:
                timeout: float, How long to try to lock for.
                delay: float, How long to wait between retries

            Raises:
                AlreadyLockedException: if the lock is already acquired.
                IOError: if the open fails.
                CredentialsFileSymbolicLinkError: if the file is a symbolic
                                                  link.
            """
            if self._locked:
                raise AlreadyLockedException('File %s is already locked' %
                                             self._filename)
            start_time = time.time()

            validate_file(self._filename)
            try:
                self._fh = open(self._filename, self._mode)
            except IOError as e:
                # If we can't access with _mode, try _fallback_mode
                # and don't lock.
                if e.errno == errno.EACCES:
                    self._fh = open(self._filename, self._fallback_mode)
                    return

            # We opened in _mode, try to lock the file.
            while True:
                try:
                    hfile = win32file._get_osfhandle(self._fh.fileno())
                    win32file.LockFileEx(
                        hfile,
                        (win32con.LOCKFILE_FAIL_IMMEDIATELY |
                         win32con.LOCKFILE_EXCLUSIVE_LOCK), 0, -0x10000,
                        pywintypes.OVERLAPPED())
                    self._locked = True
                    return
                except pywintypes.error as e:
                    if timeout == 0:
                        raise

                    # If the error is not that the file is already
                    # in use, raise.
                    if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
                        raise

                    # We could not acquire the lock. Try again.
                    if (time.time() - start_time) >= timeout:
                        logger.warn('Could not lock %s in %s seconds' % (
                            self._filename, timeout))
                        if self._fh:
                            self._fh.close()
                        self._fh = open(self._filename, self._fallback_mode)
                        return
                    time.sleep(delay) 
开发者ID:luci,项目名称:luci-py,代码行数:59,代码来源:locked_file.py


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