class_docstr: Subclasses ScriptRunner to provide some testing features.
class_docstr_tok: ["Subclasses","ScriptRunner","to","provide","some","testing","features","."]
code: def _on_script_finished(
      self,
      ctx: ScriptRunContext,
      event: ScriptRunnerEvent,
      premature_stop: bool,
  ) -> None:
      # Only call `_remove_stale_widgets`, so that the state of triggers is still
      # visible in the element tree.
      if not premature_stop:
          self._session_state._state._remove_stale_widgets(
              ctx.widget_ids_this_run
          )
  
      # Signal that the script has finished. (We use SCRIPT_STOPPED_WITH_SUCCESS
      # even if we were stopped with an exception.)
      self.on_event.send(self, event=event)
  
      # Remove orphaned files now that the script has run and files in use
      # are marked as active.
      runtime.get_instance().media_file_mgr.remove_orphaned_files()
  
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 6 for calling the LocalScriptRunner obj's underlying member method code with example usage: obj._on_script_finished(ctx, event, premature_stop) without return types