Export to GitHub

httplib2 - issue #245

cache: concurrent updates


Posted on Feb 7, 2013 by Quick Cat

One suggestion: One 'safe' way of updating the same cached file with multiple threads is to write the file under a random, temporary name and then rename it. Rename operations should be atomic.

I would suggest the following change in httplib2/init.py

class FileCache(object): ... def set(self, key, value): cacheFullPath = os.path.join(self.cache, self.safe(key)) fd, fn = tempfile.mkstemp(dir=self.cache) f = os.fdopen(fd, 'wb') f.write(value) f.close() shutil.move(fn, cacheFullPath)

I attached the modified file.

Attachments

Status: New

Labels:
Type-Defect Priority-Medium