From 0b40e518b30d4ea7131f575e2598e3810ed6a2ce Mon Sep 17 00:00:00 2001 From: Sergio Rubio Manrique Date: Thu, 10 Nov 2016 14:42:49 +0100 Subject: [PATCH] Split events in kill and pause to abort pauses on Init() --- panic/ds/PyAlarm.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/panic/ds/PyAlarm.py b/panic/ds/PyAlarm.py index d48e9f21..ab5cdbd7 100644 --- a/panic/ds/PyAlarm.py +++ b/panic/ds/PyAlarm.py @@ -379,14 +379,16 @@ def start(self): return else: del self.updateThread self.info( 'Thread Starting') - self.event.clear() + self.kill.clear() + self.pause.clear() self.updateThread = threading.Thread(None,self.updateAlarms,'PyAlarm') self.updateThread.setDaemon(True) self.updateThread.start() def stop(self): self.info( 'In PyAlarm.stop() ...') - self.event.set() + self.kill.set() + self.pause.set() self.updateThread.join(self.PollingPeriod) if self.updateThread.isAlive(): self.warning( 'Thread '+self.updateThread.getName()+' doesn''t Stop!') @@ -442,20 +444,22 @@ def get_last_values(self,alarm='',variables=None): def updateAlarms(self): self.info( 'In PyAlarm::updateAlarms ...') - self.event.clear() + self.pause.clear() + self.kill.clear() polled_attrs = [] #Alarms will not start evaluation until StartupDelay seconds has passed. if time.time()<(self.TStarted+self.StartupDelay): self.info('Alarms evaluation not started yet, waiting StartupDelay=%d seconds.'%self.StartupDelay) - self.event.wait(self.StartupDelay-(time.time()-self.TStarted)) + self.pause.wait(self.StartupDelay-(time.time()-self.TStarted)) #Checking that the background test process is running if self.worker: if not self.worker.isAlive(): self.worker.start() - self.event.wait(self.PollingPeriod) + self.pause.wait(self.PollingPeriod) #Initializing alarm values used in formulas _locals = self.update_locals(check=True) - while not self.event.isSet(): + while not self.kill.isSet(): + self.pause.clear() try: try: #self.Alarms.servers.db.get_info() @@ -466,7 +470,7 @@ def updateAlarms(self): ## This wait is here just to prevent the loop to spin continuously # The update_locals command will not allow background process to die for k in self.Alarms.servers: - self.event.wait(self.PollingPeriod/len(self.Alarms.servers)) + self.pause.wait(self.PollingPeriod/len(self.Alarms.servers)) if self.worker: _locals = self.update_locals(_locals,update=True) continue @@ -515,7 +519,7 @@ def updateAlarms(self): #Wait moved out of try/except to avoid locked waits. if VALUE is None and tag_name in self.FailedAlarms: - self.event.wait(timewait) + self.pause.wait(timewait) continue if VALUE: @@ -575,8 +579,8 @@ def updateAlarms(self): self.Alarms[tag_name]=alarm self.lock.release() ###################################################################################################################### - self.event.wait(timewait) - if not myAlarms: self.event.wait(timewait) + self.pause.wait(timewait) + if not myAlarms: self.pause.wait(timewait) self.Uncatched='' except Exception,e: @@ -584,7 +588,7 @@ def updateAlarms(self): tr=format_exc() self.error( 'Uncatched exception in PyAlarm::updateAlarmsThread:\n%s'%tr + '\n' + '='*80) self.Uncatched+=tr+'\n' - self.event.wait(timewait) + self.pause.wait(timewait) self.info( 'In updateAlarms(): Thread finished') return @@ -1012,7 +1016,8 @@ def __init__(self,cl, name): self.worker = None self.lock=threading.RLock(); - self.event=threading.Event(); + self.kill=threading.Event(); + self.pause=threading.Event(); self.threadname=name self.updateThread = None self.last_attribute_check = 0 @@ -1033,6 +1038,7 @@ def __del__(self): def delete_device(self,allow=False): self.warning( "0[Device delete_device method] for device %s"%self.get_name()) + self.pause.set() if allow: self.set_state(PyTango.DevState.INIT) self.stop() @@ -1149,6 +1155,8 @@ def init_device(self,update_properties=True,allow=True): self.start() self.info( 'Ready to accept request ...'+'<'*40) self.setLogLevel(self.LogLevel) + self.pause.clear() + self.kill.clear() except Exception,e: self.info( 'Exception in PyAlarm.init_device(): \n%s'%traceback.format_exc()) self.set_state(PyTango.DevState.FAULT)