class SingletonApp (object): ## Instance of the singleton class __inst = None #----------------------------------------------------------------------------- ## Singleton constructor. Sets up logger and eventManager def __new__(cls): if not cls.__inst: cls.__inst = super(SingletonApp,cls).__new__(cls) ## Initialise log and send info message Log(level="DEBUG").info("SingletonApp instance created") cls.__inst._setup() return cls.__inst #----------------------------------------------------------------------------- ## Destructor def __del__(): Log().info("SingletonApp deleted") #----------------------------------------------------------------------------- ## Setup the eventManager and hook "singletonApp_setup" def _setup(self): ## An instance of events.eventManager.EventManager. Initialised in # SingletonApp._setup and deleted in SingletonApp.close self.eventManager = EventManager() Log().debug("SingletonApp setup") self.eventManager.hook("singletonApp_setup") #----------------------------------------------------------------------------- ## Safe shutdown and dereference of variables. # This stops circular references stopping the garbage collection def close(self): del self.eventManager Log().info("SingletonApp closed")