This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Cristian Martinez de Morentin
Recipients Cristian Martinez de Morentin, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-05-20.11:35:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589974548.09.0.894000250375.issue40699@roundup.psfhosted.org>
In-reply-to
Content
Hi everyone,

I have found a memory leak when using Queue and Condition from threading library.

The issue can be reproduced with the following code:

========================================================
import queue
import threading


class MemoryTest(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.queue = queue.Queue()
        self.cv = threading.Condition()

    def put(self, msg):
        self.queue.put(msg)

        with self.cv:
            self.cv.notify()

    def run(self):
        while True:
            while not self.queue.empty():
                self.queue.get()
                self.queue.task_done()

            with self.cv:
                self.cv.wait_for(lambda: not self.queue.empty())
================================================================

If you run a MemoryTest object in another thread, by calling its start() method, and you send it messages by using its put() method, you will see how RAM memory usage starts increasing.

This behaviour has been observed in Windows (64 bits) with Python 3.6, 3.7 & 3.8, but not with Python 3.5.

Thank you so much.
History
Date User Action Args
2020-05-20 11:35:48Cristian Martinez de Morentinsetrecipients: + Cristian Martinez de Morentin, paul.moore, tim.golden, zach.ware, steve.dower
2020-05-20 11:35:48Cristian Martinez de Morentinsetmessageid: <1589974548.09.0.894000250375.issue40699@roundup.psfhosted.org>
2020-05-20 11:35:47Cristian Martinez de Morentinlinkissue40699 messages
2020-05-20 11:35:47Cristian Martinez de Morentincreate