Title: Memory leak in threading library with Python 3.6-3.8
Type: resource usage Stage:
Components: Windows Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Cristian Martinez de Morentin, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-05-20 11:35 by Cristian Martinez de Morentin, last changed 2020-05-20 11:35 by Cristian Martinez de Morentin.

Messages (1)
msg369443 - (view) Author: Cristian Martinez de Morentin (Cristian Martinez de Morentin) Date: 2020-05-20 11:35
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):
        self.queue = queue.Queue() = threading.Condition()

    def put(self, msg):


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

       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.
Date User Action Args
2020-05-20 11:35:48Cristian Martinez de Morentincreate