def _stop_process(self, process): """Stop the specified process :param multiprocessing.Process process: The process to stop """ if not process.is_alive(): return LOGGER.debug('Sending signal to %s (%i) to stop', process.name, process.pid) os.kill(int(process.pid), signal.SIGABRT)
def _poll(self): """Start the poll process by invoking the get_stats method of the consumers. If we hit this after another interval without fully processing, note it with a warning. """ # Check to see if we have outstanding things to poll #if self._poll_data['processes']: # LOGGER.warn('Poll interval failure for consumer(s): %r', # ', '.join(self._poll_data['processes'])) # Keep track of running consumers dead_processes = list() # Start our data collection dict self._poll_data = {'timestamp': time.time(), 'processes': list()} # Iterate through all of the consumers for process in self._active_processes: LOGGER.debug('Checking runtime state of %s', process.name) if process == multiprocessing.current_process(): LOGGER.debug('Matched current process in active_processes') continue if not process.is_alive(): LOGGER.critical('Found dead consumer %s', process.name) dead_processes.append(process.name) else: LOGGER.debug('Asking %s for stats', process.name) #self._poll_data['processes'].append(process.name) os.kill(process.pid, signal.SIGPROF) # Remove the objects if we have them for process_name in dead_processes: self._remove_process(process_name) # Check if we need to start more processes self._check_consumer_process_counts() # If we don't have any active consumers, shutdown if not self.total_process_count: LOGGER.debug('Did not find any active consumers in poll') return self._set_state(self.STATE_STOPPED) # Check to see if any consumers reported back and start timer if not #self._poll_results_check() # Start the timer again self._start_poll_timer()
def _active_processes(self): """Return a list of all active processes, pruning dead ones :rtype: list """ dead_processes = list() active_processes = multiprocessing.active_children() for process in active_processes: if not process.is_alive(): dead_processes.append(process) if dead_processes: LOGGER.debug('Found %i dead processes to remove', len(dead_processes)) for process in dead_processes: self._remove_process(process.name) active_processes.remove(process) return active_processes