title: Python to run a specific flask program until hitting another button
body: <p>I have a sweep function that returns a string of data. What I want to do is have two buttons, a start button and a stop button. When the start button is hit, the sweep function is called, and once that function is finished it is called again and again and again. Running nonstop until the stop button is hit. I'm using flask.</p>
  <p>I don't think this is a duplicate because most of the other question regarding this want it to stop at a specific time, ie. run for 45 seconds. I need mine to run continuously until the stop button is pressed.</p>
  <p>My thought process was to do something like</p>
  <pre><code>@app.route('continue_sweep', methods=[&quot;GET&quot;,&quot;POST&quot;)
  def continue_sweep():
      while (sweep_continue flag = true):
          sweep()
  </code></pre>
  <p>and then in my stop button function just have a sort of break all? I don't know if that's a thing or not, but that was my thought process.</p>
  <pre><code>@app.route('stop_sweep', methods=[&quot;GET&quot;,&quot;POST&quot;])
  def stop_sweep():
      break all --&gt;&gt; end the above sweep function here 
  </code></pre>
  <p>--------------------Updated code
  I can do something like this</p>
  <pre><code>@app.route('/start_continue_sweep', methods=[&quot;GET&quot;,&quot;POST&quot;])
  def start_continue_sweep():
      if init_tester_flag == False:
          initialize_tester()
      stop_btn_flag = False
      while (stop_btn_flag == False):
          sweep_continue_fun()
      return render_template('sweep_results.html', sweep_str = remove_err_str)
  
  def sweep_continue_fun():
      sweep_btn()
      return render_template('sweep_results.html', sweep_str = remove_err_str)
  </code></pre>
  <p>and it gives me what I want, but does not update the sweep_results.html. Is this why I would need something like what was mentioned in your answers below? Or is there an easier fix to make it update?</p>