Ref : https://github.com/python/cpython/pull/25174

https://github.com/localstack/localstack/blob/5a5edcd9d9ccbd6a56f23d71e3a1131b8c814996/localstack/utils/common.py#L324
while True:
            self.do_run_cmd()
            if INFRA_STOPPED or not self.auto_restart or not self.process or self.process.returncode == 0:
                return
            LOG.info('Restarting process (received exit code %s): %s' % (self.process.returncode, self.cmd))
    def do_run_cmd(self):
        def convert_line(line):
            line = to_str(line or '')
            return '%s\r\n' % line.strip()
        def filter_line(line):
            """ Return True if this line should be filtered, i.e., not printed """
            return '(Press CTRL+C to quit)' in line
        outfile = self.outfile or os.devnull
        if self.log_listener and outfile == os.devnull:
            outfile = subprocess.PIPE
        try:
            self.process = run(self.cmd, asynchronous=True, stdin=self.stdin, outfile=outfile,
                env_vars=self.env_vars, inherit_cwd=self.inherit_cwd, inherit_env=self.inherit_env)
            if outfile:
                if outfile == subprocess.PIPE:
                    
                    streams = ((self.process.stdout, sys.stdout), (self.process.stderr, sys.stderr))
                    for instream, outstream in streams:
                        if not instream:
                            continue
                        for line in iter(instream.readline, None):
                            
                            
                            if line in [None, '', b'']: