+ def _fetch(self, sessid):
+ while True:
+ now = int(time.time())
+ with self.lock:
+ if sessid in self.live:
+ entry = self.live[sessid]
+ else:
+ entry = self.live[sessid] = [threading.RLock(), None]
+ with entry[0]:
+ if isinstance(entry[1], session):
+ entry[1].atime = now
+ return entry[1]
+ elif entry[1] == "retired":
+ continue
+ elif entry[1] is None:
+ try:
+ thawed = self.thaw(sessid)
+ if thawed.atime + thawed.expire < now:
+ raise KeyError()
+ thawed.lock = entry[0]
+ thawed.atime = now
+ entry[1] = thawed
+ return thawed
+ finally:
+ if entry[1] is None:
+ entry[1] = "retired"
+ with self.lock:
+ del self.live[sessid]
+ else:
+ raise Exception("Illegal session entry: " + repr(entry[1]))
+