class_docstr: An interface for communicating with a ScriptRunner. Thread-safe.
  
  AppSession makes requests of a ScriptRunner through this class, and
  ScriptRunner handles those requests.
class_docstr_tok: ["An","interface","for","communicating","with","a","ScriptRunner",".","Thread-safe",".","AppSession","makes","requests","of","a","ScriptRunner","through","this","class",",","and","ScriptRunner","handles","those","requests","."]
docstr: Called by the ScriptRunner when it's about to run its script for
  the first time, and also after its script has successfully completed.
  
  If we have a RERUN request, return the request and set
  our internal state to CONTINUE.
  
  If we have a STOP request or no request, set our internal state
  to STOP.
docstr_tok: ["Called","by","the","ScriptRunner","when","it","'s","about","to","run","its","script","for","the","first","time",",","and","also","after","its","script","has","successfully","completed",".","If","we","have","a","RERUN","request",",","return","the","request","and","set","our","internal","state","to","CONTINUE",".","If","we","have","a","STOP","request","or","no","request",",","set","our","internal","state","to","STOP","."]
code: def on_scriptrunner_ready(self) -> ScriptRequest:
      """Called by the ScriptRunner when it's about to run its script for
      the first time, and also after its script has successfully completed.
  
      If we have a RERUN request, return the request and set
      our internal state to CONTINUE.
  
      If we have a STOP request or no request, set our internal state
      to STOP.
      """
      with self._lock:
          if self._state == ScriptRequestType.RERUN:
              self._state = ScriptRequestType.CONTINUE
              return ScriptRequest(
                  ScriptRequestType.RERUN, self._rerun_data
              )
  
          # If we don't have a rerun request, unconditionally change our
          # state to STOP.
          self._state = ScriptRequestType.STOP
          return ScriptRequest(ScriptRequestType.STOP)
  
imports: import threading
  from dataclasses import dataclass
  from enum import Enum
  from typing import Optional, cast
  from streamlit import util
  from streamlit.proto.WidgetStates_pb2 import WidgetStates
  from streamlit.runtime.state import coalesce_widget_states
label_desc: Use image node_id 5 for calling the ScriptRequests obj's underlying member method code with example usage: obj.on_scriptrunner_ready() and returns: ScriptRequest, ScriptRequest