import time import os 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(): msg = self.queue.get() self.queue.task_done() with self.cv: self.cv.wait_for(lambda: not self.queue.empty()) class Worker(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.memory = MemoryTest() def run(self): while True: self.memory.put('hello') time.sleep(0.001) worker = Worker() worker.memory.start() worker.start() while True: os.system(f"grep ^VmRSS /proc/{os.getpid()}/status") time.sleep(1) worker.join() worker.memory.join()