def wait_for_result()

in samcli/local/docker/container.py [0:0]


    def wait_for_result(self, full_path, event, stdout, stderr, start_timer=None):
        # NOTE(sriram-mv): Let logging happen in its own thread, so that a http request can be sent.
        # NOTE(sriram-mv): All logging is re-directed to stderr, so that only the lambda function return
        # will be written to stdout.

        # the log thread will not be closed until the container itself got deleted,
        # so as long as the container is still there, no need to start a new log thread
        if not self._logs_thread or not self._logs_thread.is_alive():
            self._logs_thread_event = self._create_threading_event()
            self._logs_thread = threading.Thread(
                target=self.wait_for_logs, args=(stderr, stderr, self._logs_thread_event), daemon=True
            )
            self._logs_thread.start()

        # wait_for_http_response will attempt to establish a connection to the socket
        # but it'll fail if the socket is not listening yet, so we wait for the socket
        self._wait_for_socket_connection()

        # start the timer for function timeout right before executing the function, as waiting for the socket
        # can take some time
        timer = start_timer() if start_timer else None
        response, is_image = self.wait_for_http_response(full_path, event, stdout)
        if timer:
            timer.cancel()

        self._logs_thread_event.wait(timeout=1)
        if isinstance(response, str):
            stdout.write_str(response)
        elif isinstance(response, bytes) and is_image:
            stdout.write_bytes(response)
        elif isinstance(response, bytes):
            stdout.write_str(response.decode("utf-8"))
        stdout.flush()
        stderr.write_str("\n")
        stderr.flush()
        self._logs_thread_event.clear()