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