Threads not exiting and program won't exit
<p>Using the script below, I cannot seem to exit the threads. The script runs smoothly without issues but never exits when done. I can still see the thread alive, I have to use <code>htop</code> to kill them or completely exit the command line.</p>

<p>How can I get this script to exit and the threads to die?</p>

<pre><code>def async_dns():
    s = adns.init()
    while True:
        dname = q.get()
        response = s.synchronous(dname,adns.rr.NS)[0]
        if response == 0:
            dot_net.append("Y")
            print(dname + ", is Y")
        elif response == 300 or response == 30 or response == 60:
            dot_net.append("N")
            print(dname + ", is N")
        elif q.empty() == True:
            q.task_done()

q = queue.Queue()
threads = []
for i in range(20):
    t = threading.Thread(target=async_dns)
    threads.append(t)
    t.start()

for name in names:
    q.put_nowait(name)
</code></pre>

<blockquote>
  <p>Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. Otherwise (block is false), return an item if one is immediately available, else raise the Empty exception (timeout is ignored in that case).</p>
</blockquote>

<p>Remember to check your queue.</p>

<p>See the document of <a href="https://docs.python.org/3/library/queue.html#module-queue" rel="nofollow">queue</a>.</p>

python multithreading