def __init__(self, name, rpc_q, terminate): """ :param name: The name of this child :type name: string :param read_q: The queue the child will read from for RPC communications from the parent process. :type read_q: multiprocessing.Queue :param write_q: The queue the child will write the results of RPC calls to. :type write_q: multiprocessing.Queue :param terminate: An event that flags ChildCore objects to shut themselves down. :type terminate: multiprocessing.Event """ Core.__init__(self) #: The name of this child self.name = name #: The :class:`multiprocessing.Event` that will be monitored #: to determine when this child should shut down. self.terminate = terminate #: The queue used for RPC communication self.rpc_q = rpc_q # override this setting so that the child doesn't try to write # the pidfile Bcfg2.Options.setup.daemon = False # ensure that the child doesn't start a perflog thread self.perflog_thread = None self._rmi = dict()
def shutdown(self): Core.shutdown(self) self.logger.info("%s: Closing RPC command queue" % self.name) self.rpc_q.close() while len(threading.enumerate()) > 1: threads = [t for t in threading.enumerate() if t != threading.current_thread()] self.logger.info("%s: Waiting for %d thread(s): %s" % (self.name, len(threads), [t.name for t in threads])) time.sleep(1) self.logger.info("%s: All threads stopped" % self.name)