title: How can I stop udp server in threading?
body: <p>I wrote a udp no echo server in my program, I used thread to running and listen some message send by others. But it seems I couldn't stop it use <code>tl.stop()</code>, when I input <code>q</code> or <code>quit</code>. Some of my code is following:</p>
  
  <pre><code>            class treadListen(threading.Thread):
                  def __init__(self):
                      self.running = True
                      threading.Thread.__init__(self)
  
                  def run(self):
                      address = ('localhost', 16666)
                      sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                      sock.bind(address)
                      while True:
                          data = sock.recv(65535)
                          print "MESSAGE:{0}".format(data)
                      sock.close()
  
                  def stop(self):
                      self.running = False
                  # end of class thread_clock
  
  
              if __name__ == "__main__":
                  tl = treadListen()
                  tl.start()
  
                  while True:
                      message = raw_input("CMD&gt;")
                      if not message:
                          print "Please input command!"
                          continue
                      elif (message == 'quit') or (message == 'q'):
                          tl.stop()
                          break
                      else:
                          print "input is {0}".format(message)
                          # do something
                          continue
                  print "[CONNECTION CLOSED!]"
  </code></pre>
  
  <p>I was trying to add <code>sock.shutdown(socket.SHUT_RDWR)</code> and <code>sock.close()</code> to def stop of class, but it doesn't work.
  How can I stop the thread safety? Thanks!</p>