One thing I just realized: where cacheLock is defined, there is a comment "When cache locks and file locks need to be held at the same time, always acquire the cache lock first.", so my guess is that this initialization should probably be moved before the "with self.fileCondition" earlier in this function...