title: Kill a Daemon Thread Whilst the Script is still Running
body: <p>My python script creates alot of threads, they are all daemon threads, I find that I get an error saying "out of memory".</p>
  
  <p><strong>How do I kill a daemon thread whilst my script/application is running?</strong></p>
  
  <p>I understand the concept of daemon threads, that they destroy themselves when my process(script or application) closes/finishes. But I want to kill some of my daemon threads whilst my script is still running to avoid the "out of memory" error.</p>
  
  <p>Will my thread below kill itself when there are no more tasks in the queue?</p>
  
  <pre><code>class ParsePageThread(threading.Thread):
      THREAD_NUM = 0
  
      def __init__(self, _queue):
          threading.Thread.__init__(self)
          self.queue       = _queue
  
      def run(self):
          while(True):
              try:
                  url = self.queue.get()
              except Queue.Empty,e:
                  return # WILL this kill the thread?
              finally:
                  self.queue.task_done()
  </code></pre>