code: def require_widgets_deltas(
      runner: LocalScriptRunner, timeout: float = 3
  ) -> None:
      """Wait for the given ScriptRunner to emit a completion event. If the timeout
      is reached, the runner will be shutdown and an error will be thrown.
      """
  
      t0 = time.time()
      while time.time() - t0 < timeout:
          time.sleep(0.001)
          if runner.script_stopped():
              return
  
      # If we get here, the runner hasn't yet completed before our
      # timeout. Create an error string for debugging.
      err_string = f"AppTest script run timed out after {timeout}(s)"
  
      # Shutdown the runner before throwing an error, so that the script
      # doesn't hang forever.
      runner.request_stop()
      runner.join()
  
      raise RuntimeError(err_string)
  
imports: from __future__ import annotations
  import os
  import time
  from typing import Any
  from urllib import parse
  from streamlit import runtime
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
  from streamlit.proto.WidgetStates_pb2 import WidgetStates
  from streamlit.runtime.forward_msg_queue import ForwardMsgQueue
  from streamlit.runtime.memory_uploaded_file_manager import MemoryUploadedFileManager
  from streamlit.runtime.scriptrunner import RerunData, ScriptRunner, ScriptRunnerEvent
  from streamlit.runtime.scriptrunner.script_cache import ScriptCache
  from streamlit.runtime.scriptrunner.script_run_context import ScriptRunContext
  from streamlit.runtime.state.safe_session_state import SafeSessionState
  from streamlit.testing.v1.element_tree import ElementTree, parse_tree_from_messages
label_desc: Use image node_id 1 for calling a global function with example usage: require_widgets_deltas(runner, timeout) without return types