How to stop daemon thread?
<p>I have a simple producer consumer application.</p>

<p>The producer is a thread that writes stuff to a queue and a consumer is a thread that reads the messages from the queue does stuff and at some points exits. </p>

<p>my producer looks a little bit like this</p>

<pre><code>def producer(queue):
    while not queue.full():
        queue.put(randint(1, 199))
</code></pre>

<p>and the consumer</p>

<pre><code>def consumer(queue):
    for i in range(100):
        print(queue.get())
        queue.task_done()
</code></pre>

<p>in my main I invoke those threads like that</p>

<pre><code>p = Thread(target=producer)
c = Thread(target=consumer)

p.daemon = True
p.start()
c.start()
c.join()
</code></pre>

<p>when <code>c</code> finishes the only remaining non deamon thread is main, what is the proper way to end those threads?</p>

<p><strong>update</strong></p>

<p>Here is the exact code that my producer is using, since the consumer is exiting and the problem lies with the producer</p>

<pre><code>def generate_random_alphanumerics(msg_queue):
    while True:
        if not msg_queue.full():
            msg_queue.put(hashlib.sha1(bytes(randint(1, 10000))).hexdigest() * 10)
        else:
            sleep(0.01)
</code></pre>

<p>is the problem that the thread is sleeping?</p>