def exit(self): """ Updates the settings file and kills the persistant storage class. This must be called when you are finished with the SettingsManager in order to clean up and stop the worker thread. Some doctests: >>> import threading >>> print threading.activeCount() 1 >>> s = SettingsManager() >>> print threading.activeCount() 2 >>> s.exit() >>> print threading.activeCount() 1 """ try: # kill the persistant storage self.__persistant_storage.exit() # update the settings file self.set({"output": "SettingsManager> Updating settings file"}) self.__settings_file_parser.update_settings_file(self.__variables) finally: self._stay_alive = False self._remote_input_queue.put(None) self.remote_task_thread.join() self._remote_input_queue.close() ThreadQueueBase.exit(self) print("SettingsManager has exited")
def exit(self): """ Note that the exit method only kills the proxy, not the master. However, it does remove the proxy from the master, closing the shared queue between them. """ task = RemoteTask(self.id, "destroy proxy", self.id) self.output_queue.put(task) ThreadQueueBase.exit(self)
def exit(self): """ Shuts down all the objects that this class created, and then kills its own internal worker thread. """ # kill own worker thread ThreadQueueBase.exit(self) try: self._camera_manager.exit() except AttributeError: pass try: self._output_task_handler.exit() except AttributeError: pass
def exit(self): """ Waits for all the outstanding OutputTasks to be completed then shuts down the processing pools and the internal worker thread. """ # kill own worker thread ThreadQueueBase.exit(self) print("OutputTaskHandler: Killed self") # shutdown the processing pools self._processing_pool.exit() self._pipelined_processing_pool.exit() print("OutputTaskHandler: Joined processing pools") # kill the network manager if (self._network_manager is not None): self._network_manager.exit() print("OutputTaskHandler: Killed network manager")
def __init__(self): ThreadQueueBase.__init__(self, name="SettingsManager") # define method to string mappings - notice that these should be the # thread safe public methods! self._methods = { "get": self.get, "set": self.set, "create": self.create, "register": self.register, "unregister": self.unregister, "operate": self.operate, "destroy proxy": self._commit_destroy_proxy, } # self._manager = Manager() # self._manager.Queue() self._remote_input_queue = multiprocessing.Queue() # create thread to handle remote tasks self.remote_task_thread = Thread(target=self._process_remote_tasks) self.remote_task_thread.start() try: # define private attributes self.__variables = {} self.__callbacks = {} self.__callback_ids = {} self._output_queues = {} # hard code settings file location and create a parser home = os.path.expanduser("~") self.__settings_file_parser = settings_file_parser.SettingsFileParser(home + "/.pysces_asi/settings.txt") # create an output variable - this is used instead of printing to stdout, making it easier # for a top layer application (e.g. a GUI) to access this data self.__create("output", "") # load settings file settings = self.__settings_file_parser.get_settings() # store settings in variables for key in list(settings.keys()): self.__create(key, settings[key]) # create persistant storage class self.__persistant_storage = persist.PersistantStorage(home + "/.pysces_asi", self) # load persistant values into variables persistant_data = self.__persistant_storage.get_persistant_data() for key in list(persistant_data.keys()): self.__create(key, persistant_data[key], persistant=True) except Exception as ex: # if an exception occurs then we need to shut down the threads and # manager before exiting self._stay_alive = False self._remote_input_queue.put(None) self.remote_task_thread.join() self._remote_input_queue.close() ThreadQueueBase.exit(self) raise ex