text: Title: Stale output from a long-running computation erroneously shows as not stale when app rerun
  Body: ### Checklist
  
  - [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
  - [X] I added a very descriptive title to this issue.
  - [X] I have provided sufficient information below to help reproduce this issue.
  
  ### Summary
  
  This is a bug report on behalf of Thiago in order to keep it tracked.
  
  When a Streamlit app with long-running computation is stopped and then re-run, old stale data from the previous run show up as if it was not stale until the old thread completes execution, at which point the data is properly cleaned up.
  
  ### Reproducible Code Example
  
  ```Python
  import platform
  import time
  
  import streamlit as st
  
  st.caption(
      f"""
  Running with Python {platform.python_version()} and Streamlit {st.__version__}.
  """
  )
  
  """
  This is an app!!
  """
  
  
  def slow_computation(x):
      st.write("Starting slow computation...")
      time.sleep(10)
      st.write("Stopping slow computation...")
      return f"Done, {x + 1}"
  
  
  out = slow_computation(1)
  
  st.write(out)
  ```
  
  
  ### Steps To Reproduce
  
  This is a Playwright test that simulates the current behavior (which is to say, this test currently passes, but should fail once the underlying issue is fixed). There are `NOTE`s inline that describe expected behavior
  
  
  ```py
  import time
  
  from playwright.sync_api import Page, expect
  
  
  def test_threading_behavior(page: Page):
      # This uses `localhost:8501` since I was running different versions of Streamlit
      # in an attempt to bisect this issue in case it was introduced at some point in time
      page.goto("http://localhost:8501/")
  
      page.get_by_text("Stopping slow computation...").wait_for(timeout=20000)
      expect(page.get_by_text("Stopping slow computation...")).to_be_visible()
  
      print(page.query_selector_all(".element-container")[0].inner_text())
  
      # At this point, the first run of the thread completed
      expect(page.get_by_text("Done, 2")).to_be_visible()
  
      # conditional logic to make it work with older versions of Streamlit
      if page.query_selector('div[data-testid="stMainMenu"]'):
          page.get_by_test_id("stMainMenu").click()
      elif page.query_selector('[id="MainMenu"]'):
          main_menu = page.query_selector('[id="MainMenu"]')
          if main_menu:
              main_menu.click()
  
      # Now we are re-running the app
      page.get_by_text("Rerun").click()
  
      # Some time delay so that the new thread is started and some elements are marked as stable
      time.sleep(2)
  
      # Expect some of the elements to be marked as stale
      assert len(page.query_selector_all('div[data-stale="true"]')) == 2
      expect(page.get_by_text("Stopping slow computation...")).to_be_visible()
      expect(page.get_by_text("Done, 2")).to_be_visible()
  
      # Stop the new thread
      page.get_by_role("button", name="Stop").click()
  
      time.sleep(2)
  
      # NOTE: This should not pass. Stale elements shouldn't suddenly be marked as not stale
      # since these are old results from a thread that was supposed to have been stopped
      assert len(page.query_selector_all('div[data-stale="true"]')) == 0
  
      # NOTE: This should not pass. It is unexpected that the results from the old thread
      # are still showing up, despite us re-running
      expect(page.get_by_text("Stopping slow computation...")).to_be_visible()
      expect(page.get_by_text("Done, 2")).to_be_visible()
  
      # wait for the thread to complete
      time.sleep(10)
  
      # Expect old elements to be cleared out
      expect(page.get_by_text("Stopping slow computation...")).not_to_be_visible()
      expect(page.get_by_text("Done, 2")).not_to_be_visible()
  ```
  
  ### Expected Behavior
  
  _No response_
  
  ### Current Behavior
  
  _No response_
  
  ### Is this a regression?
  
  - [ ] Yes, this used to work in a previous version.
  
  ### Debug info
  
  - Streamlit version: 1.0.0 -> 1.40.1 all show this behavior (I didn't test versions before)
  - Python version: 3.8
  - Operating System: Mac
  - Browser: Chrome
  
  
  ### Additional Information
  
  _No response_