X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsession.py;h=9e91ad9b4b71067b249dfa7b0a7261d4f778586f;hb=13b37ed32a4a376d2d6e89f5fa9eb97da5146cb7;hp=513725d12d039dff43959fd28e95182438ea2343;hpb=b409a33843abb3221edd27016558c39cf33a6510;p=wrw.git diff --git a/wrw/session.py b/wrw/session.py index 513725d..9e91ad9 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -76,7 +76,6 @@ class db(object): self.cookiename = cookiename self.path = path self.lock = threading.Lock() - self.lastuse = 0 self.cthread = None self.freezetime = 3600 @@ -99,18 +98,17 @@ class db(object): def cleanloop(self): try: - lastuse = self.lastuse - while self.lastuse >= lastuse: - lastuse = self.lastuse + while True: time.sleep(300) self.clean() + if len(self.live) == 0: + break finally: with self.lock: self.cthread = None def fetch(self, req): now = int(time.time()) - self.lastuse = now sessid = cookie.get(req, self.cookiename) with self.lock: if self.cthread is None: @@ -131,18 +129,17 @@ class db(object): except KeyError: sess = session() self.live[sess.id] = sess - req.oncommit(self.addcookie) + sess.new = True req.oncommit(self.ckfreeze) return sess - def addcookie(self, req): - sess = req.item(self.fetch) - cookie.add(req, self.cookiename, sess.id, self.path) - def ckfreeze(self, req): sess = req.item(self.fetch) if sess.dirty(): try: + if getattr(sess, "new", False): + cookie.add(req, self.cookiename, sess.id, self.path) + del sess.new self.freeze(sess) except: pass