Changeset 5693

Show
Ignore:
Timestamp:
11/17/08 11:08:46 (2 months ago)
Author:
carndt
Message:

Add some sanity/paranoia checks & locks in VisitManager? thread

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/visit/api.py

    r5495 r5693  
    141141    if not hasattr(cherrypy.root, "_cp_filters"): 
    142142        cherrypy.root._cp_filters = list() 
    143     cherrypy.root._cp_filters.append(visit_filter) 
     143    if not visit_filter in cherrypy.root._cp_filters: 
     144        cherrypy.root._cp_filters.append(visit_filter) 
    144145 
    145146def shutdown_extension(): 
     
    297298        self.lock = threading.Lock() 
    298299        self._shutdown = threading.Event() 
    299         self.interval = 30 
    300         self.setDaemon(True) 
     300        self.interval = 30.0 
    301301        # We need to create the visit model before the manager thread is 
    302302        # started. 
    303303        self.create_model() 
     304        self.setDaemon(True) 
    304305        self.start() 
    305306 
     
    331332 
    332333    def shutdown(self, timeout=None): 
    333         self._shutdown.set() 
    334         self.join(timeout) 
     334        try: 
     335            self.lock.acquire() 
     336            self._shutdown.set() 
     337            self.join(timeout) 
     338        finally: 
     339            self.lock.release() 
    335340        if self.isAlive(): 
    336341            log.error("Visit Manager thread failed to shutdown.") 
     
    339344        while not self._shutdown.isSet(): 
    340345            self.lock.acquire() 
     346            if self._shutdown.isSet(): 
     347                continue 
    341348            queue = None 
    342349            try: 
     
    345352                    queue = self.queue.copy() 
    346353                    self.queue.clear() 
     354                if queue is not None: 
     355                    self.update_queued_visits(queue) 
    347356            finally: 
    348357                self.lock.release() 
    349             if queue is not None: 
    350                 self.update_queued_visits(queue) 
    351358            self._shutdown.wait(self.interval)