Changeset 2434
- Timestamp:
- 06/14/09 16:39:17
- Files:
-
- branches/python3/cherrypy/lib/sessions.py (modified) (3 diffs)
- branches/python3/cherrypy/process/plugins.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/python3/cherrypy/lib/sessions.py
r2427 r2434 17 17 except ImportError: 18 18 from sha import new as sha 19 import sys 19 20 import time 20 21 import threading … … 158 159 # so that tool config can be accessed inside the method. 159 160 t = cherrypy.process.plugins.Monitor( 160 cherrypy.engine, self.clean_up, self.clean_freq * 60) 161 cherrypy.engine, self.clean_up, self.clean_freq * 60, 162 name='Session cleanup') 161 163 t.subscribe() 162 164 cls.clean_thread = t … … 239 241 """Clean up expired sessions.""" 240 242 now = datetime.datetime.now() 241 for id, (data, expiration_time) in self.cache.items():242 if expiration_time < now:243 for id, (data, expiration_time) in list(self.cache.items()): 244 if expiration_time <= now: 243 245 try: 244 246 del self.cache[id] branches/python3/cherrypy/process/plugins.py
r2412 r2434 383 383 if self.finished.isSet(): 384 384 return 385 self.function(*self.args, **self.kwargs) 385 try: 386 self.function(*self.args, **self.kwargs) 387 except Exception as x: 388 self.bus.log("Error in perpetual timer thread function %r." % 389 self.function, level=40, traceback=True) 390 # Quit on first error to avoid massive logs. 391 raise 386 392 387 393 … … 396 402 frequency = 60 397 403 398 def __init__(self, bus, callback, frequency=60 ):404 def __init__(self, bus, callback, frequency=60, name=None): 399 405 SimplePlugin.__init__(self, bus) 400 406 self.callback = callback 401 407 self.frequency = frequency 402 408 self.thread = None 409 self.name = name 403 410 404 411 def start(self): 405 412 """Start our callback in its own perpetual timer thread.""" 406 413 if self.frequency > 0: 407 threadname = self. __class__.__name__414 threadname = self.name or self.__class__.__name__ 408 415 if self.thread is None: 409 416 self.thread = PerpetualTimer(self.frequency, self.callback) 417 self.thread.bus = self.bus 410 418 self.thread.setName(threadname) 411 419 self.thread.start() … … 418 426 """Stop our callback's perpetual timer thread.""" 419 427 if self.thread is None: 420 self.bus.log("No thread running for %s." % self. __class__.__name__)428 self.bus.log("No thread running for %s." % self.name or self.__class__.__name__) 421 429 else: 422 430 if self.thread is not threading.currentThread():

