def __init__(self,beamline='C',notify=None,reconnect=None,logger=None): logger.info('Q315_Monitor::__init__ beamline: %s' % beamline) #initialize the thread threading.Thread.__init__(self) #passed-in variables self.notify = notify self.reconnect = reconnect self.beamline = beamline self.logger = logger #for stopping/starting self.Go = True #The modification times self.xf_time = 0 self.mar_time = 0 #set the adsc server if beamline in secrets.keys(): self.logger.debug('Attmepting to conect to adsc monitor at %s' % secrets[beamline]['adsc_server']) self.server = xmlrpclib.Server(secrets[beamline]['adsc_server']) print self.server #if the assigned beamline is not in the settings, use the localhost else: self.server = xmlrpclib.Server('http://127.0.0.1:8001') #register for shutdown atexit.register(self.Stop) #start the thread self.start()
def run(self): if (self.logger): self.logger.debug('Hf4m_Monitor::run') else: print 'Hf4m_Monitor::run' #try: #set the adsc server if self.beamline in secrets.keys(): if self.logger: self.logger.debug('Attempting to connect to Redis database at at %s' % secrets[self.beamline]['remote_redis_ip']) else: print 'Attempting to connect to Redis database at at %s' % secrets[self.beamline]['remote_redis_ip'] self.red = pysent.RedisManager(sentinel_host="remote.nec.aps.anl.gov", sentinel_port=26379, master_name="remote_master") #if the assigned beamline is not in the settings, use the localhost else: self.red = pysent.RedisManager(sentinel_host="remote.nec.aps.anl.gov", sentinel_port=26379, master_name="remote_master") #except: # if (self.logger): # self.logger.debug('Exception in starting Hf4m_Monitor::run') # else: # print 'Exception in starting Hf4m_Monitor::run' time.sleep(5) self.run() # Watch the imagelist image_list = "images_collected_"+self.beamline if self.logger: self.logger.debug('Hf4m_Monitor::Start listening') else: print 'Hf4m_Monitor::Start listening' while (self.Go): try: #try to pop the oldest image off the list new_image = self.red.rpop(image_list) if (new_image): if self.logger: self.logger.debug('Hf4m_Monitor::new image %s' % new_image) else: print 'Hf4m_Monitor::new image %s' % new_image if (new_image.endswith('.cbf')): self.notify(("NEW HF4M IMAGE", new_image)) except: if self.logger: self.logger.exception('Exception in while loop') else: print 'Exception in while loop' time.sleep(5) #slow it down a little time.sleep(0.1)