diff options
author | Thomas B Thompson <tbent@spice.(none)> | 2011-01-10 22:23:49 -0500 |
---|---|---|
committer | Thomas B Thompson <tbent@spice.(none)> | 2011-01-10 22:23:49 -0500 |
commit | bb1d982669c44a990ffc926f4666b6aa72237619 (patch) | |
tree | b3d3e3e48423d89658cc11608d17bbee5d92a8d8 /operationscore/SmootCoreObject.py | |
parent | 21e961d8074570cca27b2661582d728be85b18b9 (diff) |
Worked on getting the threading stuff consolidated in ThreadedSmootCoreObject. Also set up a decent system for SmootCoreObjects to kill the whole application in a managed fashion.
Diffstat (limited to 'operationscore/SmootCoreObject.py')
-rw-r--r-- | operationscore/SmootCoreObject.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/operationscore/SmootCoreObject.py b/operationscore/SmootCoreObject.py index c481776..8b36f4d 100644 --- a/operationscore/SmootCoreObject.py +++ b/operationscore/SmootCoreObject.py @@ -2,39 +2,62 @@ import pdb import threading import thread import util.Config as configGetter + class SmootCoreObject(object): def __init__(self, argDict, skipValidation = False): + self.dieListeners = [] self.argDict = argDict self.validateArgs(self.className()+'.params') self.lock = thread.allocate_lock() - self.init() #call init of inheriting class #put everything into attributes for speed for key in argDict: setattr(self, key, argDict[key]) + self.init() #call init of inheriting class # self.__setitem__ = self.argDict.__setitem__ # self.__getitem__ = self.argDict.__getitem__ + def init(self): pass + def acquireLock(self): - self.lock = thread.allocate_lock() #TODO: fix. + self.lock = thread.allocate_lock() #TODO: fix. -- investigate this, it should only have to be run once in the initialization. self.lock.acquire() + def releaseLock(self): self.lock.release() + def className(self): return self.__class__.__name__ + def __setitem__(self,k, item): self.argDict[k] = item + def __getitem__(self, item): if item in self.argDict: return self.argDict[item] else: return None + def __getiter__(self): return self.argDict.__getiter__() + def validateArgs(self, argFileName): self.validateArgDict(configGetter.loadParamRequirementDict(argFileName))#util #caches for us, woo! + def validateArgDict(self, validationDict): for item in validationDict: if not item in self.argDict: raise Exception(validationDict[item]) + + def addDieListener(self, listener): + if listener not in self.dieListeners: + self.dieListeners.append(listener) + + def removeDieListener(self, listener): + if listener in self.dieListeners: + self.dieListeners.remove(listener) + + def die(self): + for listener in self.dieListeners: + listener.handleDie(self) |