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


Python locked_file.LockedFile方法代码示例

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


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

示例1: __init__

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def __init__(self, max_age):
      """Constructor.

      Args:
        max_age: Cache expiration in seconds.
      """
      self._max_age = max_age
      self._file = os.path.join(tempfile.gettempdir(), FILENAME)
      f = LockedFile(self._file, 'a+', 'r')
      try:
        f.open_and_lock()
        if f.is_locked():
          _read_or_initialize_cache(f)
        # If we can not obtain the lock, other process or thread must
        # have initialized the file.
      except Exception as e:
        LOGGER.warning(e, exc_info=True)
      finally:
        f.unlock_and_close() 
开发者ID:taers232c,项目名称:GAMADV-XTD,代码行数:21,代码来源:file_cache.py

示例2: get

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def get(self, url):
    f = LockedFile(self._file, 'r+', 'r')
    try:
      f.open_and_lock()
      if f.is_locked():
        cache = _read_or_initialize_cache(f)
        if url in cache:
          content, t = cache.get(url, (None, 0))
          if _to_timestamp(datetime.datetime.now()) < t + self._max_age:
            return content
        return None
      else:
        LOGGER.debug('Could not obtain a lock for the cache file.')
        return None
    except Exception as e:
      LOGGER.warning(e, exc_info=True)
    finally:
      f.unlock_and_close() 
开发者ID:taers232c,项目名称:GAMADV-XTD,代码行数:20,代码来源:file_cache.py

示例3: set

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def set(self, url, content):
    f = LockedFile(self._file, 'r+', 'r')
    try:
      f.open_and_lock()
      if f.is_locked():
        cache = _read_or_initialize_cache(f)
        cache[url] = (content, _to_timestamp(datetime.datetime.now()))
        # Remove stale cache.
        for k, (_, timestamp) in list(cache.items()):
          if _to_timestamp(datetime.datetime.now()) >= timestamp + self._max_age:
            del cache[k]
        f.file_handle().truncate(0)
        f.file_handle().seek(0)
        json.dump(cache, f.file_handle())
      else:
        LOGGER.debug('Could not obtain a lock for the cache file.')
    except Exception as e:
      LOGGER.warning(e, exc_info=True)
    finally:
      f.unlock_and_close() 
开发者ID:taers232c,项目名称:GAMADV-XTD,代码行数:22,代码来源:file_cache.py

示例4: __init__

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def __init__(self, filename, warn_on_readonly=True):
    """Initialize the class.

    This will create the file if necessary.
    """
    self._file = LockedFile(filename, 'r+b', 'rb')
    self._thread_lock = threading.Lock()
    self._read_only = False
    self._warn_on_readonly = warn_on_readonly

    self._create_file_if_needed()

    # Cache of deserialized store. This is only valid after the
    # _MultiStore is locked or _refresh_data_cache is called. This is
    # of the form of:
    #
    # ((key, value), (key, value)...) -> OAuth2Credential
    #
    # If this is None, then the store hasn't been read yet.
    self._data = None 
开发者ID:REMAPApp,项目名称:REMAP,代码行数:22,代码来源:multistore_file.py

示例5: __init__

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def __init__(self, filename, warn_on_readonly=True):
        """Initialize the class.

        This will create the file if necessary.
        """
        self._file = LockedFile(filename, 'r+', 'r')
        self._thread_lock = threading.Lock()
        self._read_only = False
        self._warn_on_readonly = warn_on_readonly

        self._create_file_if_needed()

        # Cache of deserialized store. This is only valid after the
        # _MultiStore is locked or _refresh_data_cache is called. This is
        # of the form of:
        #
        # ((key, value), (key, value)...) -> OAuth2Credential
        #
        # If this is None, then the store hasn't been read yet.
        self._data = None 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:22,代码来源:multistore_file.py

示例6: __init__

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def __init__(self, max_age):
      """Constructor.

      Args:
        max_age: Cache expiration in seconds.
      """
      self._max_age = max_age
      self._file = os.path.join(tempfile.gettempdir(), FILENAME)
      f = LockedFile(self._file, 'a+', 'r')
      try:
        f.open_and_lock()
        if f.is_locked():
          _read_or_initialize_cache(f)
        # If we can not obtain the lock, other process or thread must
        # have initialized the file.
      except Exception as e:
        logging.warning(e, exc_info=True)
      finally:
        f.unlock_and_close() 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:21,代码来源:file_cache.py

示例7: get

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def get(self, url):
    f = LockedFile(self._file, 'r+', 'r')
    try:
      f.open_and_lock()
      if f.is_locked():
        cache = _read_or_initialize_cache(f)
        if url in cache:
          content, t = cache.get(url, (None, 0))
          if _to_timestamp(datetime.datetime.now()) < t + self._max_age:
            return content
        return None
      else:
        logger.debug('Could not obtain a lock for the cache file.')
        return None
    except Exception as e:
      logger.warning(e, exc_info=True)
    finally:
      f.unlock_and_close() 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:20,代码来源:file_cache.py

示例8: set

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def set(self, url, content):
    f = LockedFile(self._file, 'r+', 'r')
    try:
      f.open_and_lock()
      if f.is_locked():
        cache = _read_or_initialize_cache(f)
        cache[url] = (content, _to_timestamp(datetime.datetime.now()))
        # Remove stale cache.
        for k, (_, timestamp) in list(cache.items()):
          if _to_timestamp(datetime.datetime.now()) >= timestamp + self._max_age:
            del cache[k]
        f.file_handle().truncate(0)
        f.file_handle().seek(0)
        json.dump(cache, f.file_handle())
      else:
        logger.debug('Could not obtain a lock for the cache file.')
    except Exception as e:
      logger.warning(e, exc_info=True)
    finally:
      f.unlock_and_close() 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:22,代码来源:file_cache.py

示例9: __init__

# 需要导入模块: from oauth2client import locked_file [as 别名]
# 或者: from oauth2client.locked_file import LockedFile [as 别名]
def __init__(self, filename, warn_on_readonly=True):
    """Initialize the class.

    This will create the file if necessary.
    """
    self._file = LockedFile(filename, 'r+', 'r')
    self._thread_lock = threading.Lock()
    self._read_only = False
    self._warn_on_readonly = warn_on_readonly

    self._create_file_if_needed()

    # Cache of deserialized store. This is only valid after the
    # _MultiStore is locked or _refresh_data_cache is called. This is
    # of the form of:
    #
    # ((key, value), (key, value)...) -> OAuth2Credential
    #
    # If this is None, then the store hasn't been read yet.
    self._data = None 
开发者ID:jzp820927,项目名称:Deploy_XXNET_Server,代码行数:22,代码来源:multistore_file.py


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