title: Understanding Python Queues and Setting threads to run as a Daemon thread
body: <p>Lets say I have the below code:</p>
  
  <pre><code>import Queue
  import threading
  import time
  
  def basic_worker(queue, thread_name):
      while True:
         if queue.empty(): break
  
         print "Starting %s" % (threading.currentThread().getName()) + "\n"
         item = queue.get()
         ##do_work on item which might take 10-15 minutes to complete
         queue.task_done()
  
         print "Ending %s" % (threading.currentThread().getName()) + "\n"
  
  
  def basic(queue):
  # http://docs.python.org/library/queue.html
  
      for i in range(10):
         t = threading.Thread(target=basic_worker,args=(queue,tName,))
         t.daemon = True
         t.start()
      queue.join()       # block until all tasks are done
      print 'got here' + '\n'
  
  queue = Queue.Queue()
  
  for item in range(4):
       queue.put(item)
  
  
  
  basic(queue)
  
  
  print "End of program"
  </code></pre>
  
  <p>My question is, if I set <code>t.daemon = True</code> will it exit the code killing the threads that are taking 10-15 minutes to do some work on the <code>item</code> from the queue? Because from what I have read it says that the program will exit if there are any daemonic threads alive. My understanding is that the threads working on the item taking a long time will also exit incompletely. If I don't set <code>t.daemon = True</code> my program hangs forever and doesn't exit when there are no items in the queue.</p>