title: How to properly stop python threads?
body: <p>I'm new in Python. This is my code:</p>
  
  <pre><code>import logging
  logging.basicConfig(level = logging.DEBUG, format = "[%(levelname)s] (%(threadName)-10s) %(message)s")
  import threading
  import time
  
  def thread1():
      for i in range(0, 10, 2):
          logging.debug(i)
          time.sleep(1)
  
  
  def thread2():
      for i in range(10, 20):
          logging.debug(i)
          time.sleep(1)
  
  t1 = threading.Thread(name = "thread1", target = thread1)
  t1.setDaemon(True)
  t1.start()
  
  t2 = threading.Thread(name = "thread2", target = thread2)
  t2.setDaemon(True)
  t2.start()
  </code></pre>
  
  <p>When I copied the code and pasted it into a python command line prompt, I got the following result.</p>
  
  <p><img src="https://i.stack.imgur.com/Xat5t.png" alt="enter image description here"></p>
  
  <p>As you can see, the 2 threads already completed but it seems the program does not exit ( I did not get the command prompt back). I think it relates to my code that did not property end the threads. Is that true? How to fixed this issue?
  Thanks.</p>