def _get_cached_result(self, filename): inf = open(filename, 'rb') # get a lock on the file portable_locker.lock(inf, portable_locker.LOCK_SH) expire = cPickle.load(inf) result = cPickle.load(inf) # release the lock portable_locker.unlock(inf) inf.close() return (expire, result)
def _save_result(self, filename, *args, **kwds): result = self.thecallable(*args, **kwds) # save the serialized result in the file outf = open(filename, 'w') # file write lock portable_locker.lock(outf, portable_locker.LOCK_EX) cPickle.dump(time.time(), outf) cPickle.dump(result, outf) # release the lock portable_locker.unlock(outf) outf.close() return result