title: Only trigger thread when value changes (python)
body: <p>I'm working on something that reads commands from a stream of data. I got stuck trying to work out making a re-usable non-blocking countdown in Python that works off a trigger. So I started a small program w/ just keyboard input and some basic threading to work out the logic. I found a few posts, and this post (<a href="https://stackoverflow.com/questions/30825811/how-to-create-a-trigger-with-threading-timer">How to create a trigger with threading.Timer?</a>) and it was very helpful. But I need some help with another part.</p>
  
  <p>Right now my logic is along the lines of: "Each time the value of command is 1 call start"</p>
  
  <p>How do I update my logic to be:
  "if value of command is 1 call start, do not call start again as long as the value of command remains 1.</p>
  
  <p>So its more of a value change detection than a normal if/else, or I have to track a boolean somewhere. I'm just not sure how to approach it. </p>
  
  <pre><code>#! /usr/bin/env python
  
  import time
  import threading
  import random
  from random import randint
  import logging
  from sys import argv
  
  
  logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s')
  
  def countdown(pName,command):
      print("{0} countdown - command{1} ".format(pName,command))
      retry = 0
      while True:
          print("{0}:{1}".format(pName,retry))
          retry += 1
          if retry &gt; randint(5,10):
              break
          time.sleep(1)
      print("{0} ended".format(pName))
  
  def start(pName,command):
      print("starting countdown for: ",pName)
      t = threading.Thread(target=countdown,args=(pName,command))
      t.setName(pName)
      t.setDaemon(True)
      t.start()
  
  
  if __name__ == "__main__":
  
      while 1:
          command = int(input("[1 or 2] &gt;"))
          if command == 1:
              start("Salad",command)
  
          elif command == 2:
              start("Bingo",command)
  </code></pre>
  
  <p>This is pretty brute right now, but its just a first past to try and puzzle it out. </p>
  
  <p>Thanks! </p>