title: How to stop a looping thread in Python?
body: <p>What's the proper way to tell a looping thread to stop looping? </p>
  
  <p>I have a fairly simple program that pings a specified host in a separate <code>threading.Thread</code> class. In this class it sleeps 60 seconds, the runs again until the application quits.</p>
  
  <p>I'd like to implement a 'Stop' button in my <code>wx.Frame</code> to ask the looping thread to stop. It doesn't need to end the thread right away, it can just stop looping once it wakes up. </p>
  
  <p>Here is my <code>threading</code> class (note: I haven't implemented looping yet, but it would likely fall under the run method in PingAssets)</p>
  
  <pre><code>class PingAssets(threading.Thread):
      def __init__(self, threadNum, asset, window):
          threading.Thread.__init__(self)
          self.threadNum = threadNum
          self.window = window
          self.asset = asset
  
      def run(self):
          config = controller.getConfig()
          fmt = config['timefmt']
          start_time = datetime.now().strftime(fmt)
          try:
              if onlinecheck.check_status(self.asset):
                  status = "online"
              else:
                  status = "offline"
          except socket.gaierror:
              status = "an invalid asset tag."
          msg =("{}: {} is {}.   \n".format(start_time, self.asset, status))
          wx.CallAfter(self.window.Logger, msg)
  </code></pre>
  
  <p>And in my wxPyhton Frame I have this function called from a Start button:</p>
  
  <pre><code>def CheckAsset(self, asset):
          self.count += 1
          thread = PingAssets(self.count, asset, self)
          self.threads.append(thread)
          thread.start()
  </code></pre>