import threading import multiprocessing import atexit class MyClass: def __init__(self): self.queue = None self.thread = None def start(self): # Use a SimpleQueue(): no error self.queue = multiprocessing.Queue() self.thread = threading.Thread(target=self.queued_writer, daemon=True) self.thread.start() # Remove this: no error self.queue.put("message") def queued_writer(self): while 1: msg = self.queue.get() print("Message:", msg) if msg is None: break def stop(self): self.queue.put(None) self.thread.join() instance = MyClass() atexit.register(instance.stop) # Put this before register: no error instance.start()