def on_timeout_expired(timeout): global timed_out try: LOG.debug("Starting process wait inside timeout handler.") process.wait(timeout=timeout) except subprocess.TimeoutExpired: # Command has timed out, kill the process and propagate the error. # Note: We explicitly set the returncode to indicate the timeout. LOG.debug("Command execution timeout reached.") # NOTE: It's important we set returncode twice - here and below to avoid race in this # function because "kill_func()" is async and "process.kill()" is not. process.returncode = TIMEOUT_EXIT_CODE if kill_func: LOG.debug("Calling kill_func.") kill_func(process=process) else: LOG.debug("Killing process.") process.kill() # NOTE: It's imporant to set returncode here as well, since call to process.kill() sets # it and overwrites it if we set it earlier. process.returncode = TIMEOUT_EXIT_CODE if read_stdout_func and read_stderr_func: LOG.debug("Killing read_stdout_thread and read_stderr_thread") concurrency.kill(read_stdout_thread) concurrency.kill(read_stderr_thread)
def on_timeout_expired(timeout): global timed_out try: LOG.debug('Starting process wait inside timeout handler.') process.wait(timeout=timeout) except subprocess.TimeoutExpired: # Command has timed out, kill the process and propagate the error. # Note: We explicitly set the returncode to indicate the timeout. LOG.debug('Command execution timeout reached.') if kill_func: LOG.debug('Calling kill_func.') kill_func(process=process) else: LOG.debug('Killing process.') process.kill() # NOTE: It's imporant to set returncode here, since call to kill() # sets it and overwrites it if we set it earlier process.returncode = TIMEOUT_EXIT_CODE if read_stdout_func and read_stderr_func: LOG.debug('Killing read_stdout_thread and read_stderr_thread') concurrency.kill(read_stdout_thread) concurrency.kill(read_stderr_thread)
def _spin_container_and_wait(self, sensors): exit_code = 0 try: self._sensor_container = ProcessSensorContainer( sensors=sensors, single_sensor_mode=self._single_sensor_mode) self._container_thread = concurrency.spawn( self._sensor_container.run) LOG.debug('Starting sensor CUD watcher...') self._sensors_watcher.start() exit_code = self._container_thread.wait() LOG.error('Process container quit with exit_code %d.', exit_code) LOG.error('(PID:%s) SensorContainer stopped.', os.getpid()) except (KeyboardInterrupt, SystemExit): self._sensor_container.shutdown() self._sensors_watcher.stop() LOG.info('(PID:%s) SensorContainer stopped. Reason - %s', os.getpid(), sys.exc_info()[0].__name__) concurrency.kill(self._container_thread) self._container_thread = None return exit_code return exit_code
def on_timeout_expired(timeout): global timed_out try: LOG.debug("Starting process wait inside timeout handler.") process.wait(timeout=timeout) except subprocess.TimeoutExpired: # Command has timed out, kill the process and propagate the error. # Note: We explicitly set the returncode to indicate the timeout. LOG.debug("Command execution timeout reached.") process._timed_out = True if kill_func: LOG.debug("Calling kill_func.") kill_func(process=process) else: LOG.debug("Killing process.") process.kill() process.wait() process._timed_out = True if read_stdout_func and read_stderr_func: LOG.debug("Killing read_stdout_thread and read_stderr_thread") concurrency.kill(read_stdout_thread) concurrency.kill(read_stderr_thread)
def stop(self): LOG.debug('Shutting down sensor watcher.') try: if self._updates_thread: self._updates_thread = concurrency.kill(self._updates_thread) if self.connection: channel = self.connection.channel() bound_sensor_watch_q = self._sensor_watcher_q(channel) try: bound_sensor_watch_q.delete() except: LOG.error('Unable to delete sensor watcher queue: %s', self._sensor_watcher_q) finally: if self.connection: self.connection.release()
def stop(self): try: self._updates_thread = concurrency.kill(self._updates_thread) self._load_thread = concurrency.kill(self._load_thread) finally: self.connection.release()