Esempio n. 1
0
def append(i):
    random.seed()
    file('test.db', 'ab').write('% 3i %s\n' % (i, os.getpid()))
    with LockedFile(central_file) as size_file:
        current_value = int(size_file.read())
        size_file.seek(0)
        size_file.write('%i' % (i + current_value))
Esempio n. 2
0
  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