def run(self):
self.start()<EOL>timeout = self._stop_flag_timeout<EOL>health_check_ts = time.time()<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>self.stop_flag.wait(timeout=timeout)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>self._logger.info('<STR_LIT>')<EOL>self.stop(graceful=True)<EOL><DEDENT>except:<EOL><INDENT>self._logger.exception('<STR_LIT>')<EOL>self.stop()<EOL><DEDENT>else:<EOL><INDENT>if self._received_signal:<EOL><INDENT>self.stop(graceful=self._graceful)<EOL><DEDENT><DEDENT>if self.stop_flag.is_set():<EOL><INDENT>break<EOL><DEDENT>if self._health_check:<EOL><INDENT>now = time.time()<EOL>if now >= health_check_ts + self._health_check_interval:<EOL><INDENT>health_check_ts = now<EOL>self.check_worker_health()<EOL><DEDENT><DEDENT><DEDENT>if self._restart:<EOL><INDENT>self._logger.info('<STR_LIT>')<EOL>python = sys.executable<EOL>os.execl(python, python, *sys.argv)<EOL><DEDENT>else:<EOL><INDENT>self._logger.info('<STR_LIT>')<EOL><DEDENT>
Run the consumer.