def run(self): """ @requires: self.isDaemon() == True @summary: This thread serves forever. As long as EVENT_MCX_UPDATES_AVAILABLE is not set this thread will look every CONFIG_CHECKUPDATE_INTERVAL seconds for new updates until found. If updates were found, it will fire EVENT_MCX_UPDATES_AVAILABLE and wait until this event becomes cleared. """ # serve forever while self.isDaemon(): # and event flag not cleared by now if not EVENT_MCX_UPDATES_AVAILABLE.isSet(): # ensure we do not operate on an invalid object self.__cursor = None self.__clearUpdates() try: # make sure connection is established self.persistent.connect() # check for updates only, if connection is established if self.persistent.connected(): self.__cursor = self.persistent.getCursor() # check for updates self.__checkForUpdates() # disconnect properly self.persistent.disconnect() else: raise ConnectionException(DATABASE_SERVER_NOT_AVAILABLE) # no database available # let's handle the recover thread and wait for it except ConnectionException, (error): print "%s fired EVENT_MCX_DATABASE_LOST caused by: %s" % (self.getName(), error) # handle events EVENT_MCX_DATABASE_RECOVERED.clear() EVENT_MCX_DATABASE_LOST.set() EVENT_MCX_DATABASE_RECOVERED.wait() # repeat this in a given interval and sleep in the meantime :) sleep(CONFIG_CHECKUPDATE_INTERVAL)