Changeset 1435
- Timestamp:
- 11/18/06 13:19:39
- Files:
-
- trunk/cherrypy/lib/sessions.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/sessions.py
r1426 r1435 21 21 import cherrypy 22 22 from cherrypy.lib import http 23 24 25 class PerpetualTimer(threading._Timer): 26 27 def run(self): 28 while True: 29 self.finished.wait(self.interval) 30 if self.finished.isSet(): 31 return 32 self.function(*self.args, **self.kwargs) 23 33 24 34 … … 53 63 self.id = None 54 64 55 def clean_cycle(self):56 """Clean up expired sessions at regular intervals."""57 # clean_thread is both a cancelable Timer and a flag.58 if self.clean_thread:59 self.clean_up()60 t = threading.Timer(self.clean_freq, self.clean_cycle)61 self.__class__.clean_thread = t62 t.start()63 64 65 def clean_interrupt(cls): 65 """Stop the expired-session cleaning cycle."""66 """Stop the expired-session cleaning timer.""" 66 67 if cls.clean_thread: 67 68 cls.clean_thread.cancel() 69 cls.clean_thread.join() 68 70 cls.clean_thread = None 69 71 clean_interrupt = classmethod(clean_interrupt) … … 111 113 self.loaded = True 112 114 115 # Stick the clean_thread in the class, not the instance. 116 # The instances are created and destroyed per-request. 113 117 cls = self.__class__ 114 118 if not cls.clean_thread: 115 119 cherrypy.engine.on_stop_engine_list.append(cls.clean_interrupt) 116 # Use the instance to call clean_cycle so tool config 117 # can be accessed inside the method. 118 cls.clean_thread = t = threading.Timer(self.clean_freq, 119 self.clean_cycle) 120 # clean_up is in instancemethod and not a classmethod, 121 # so tool config can be accessed inside the method. 122 t = PerpetualTimer(self.clean_freq, self.clean_up) 123 t.setName("CP Session Cleanup") 124 cls.clean_thread = t 120 125 t.start() 121 126

