Script stuck on exit when using atexit to terminate threads
问题 I'm playing around with threads on python 3.7.4, and I want to use atexit to register a cleanup function that will (cleanly) terminate the threads. For example: # example.py import threading import queue import atexit import sys Terminate = object() class Worker(threading.Thread): def __init__(self): super().__init__() self.queue = queue.Queue() def send_message(self, m): self.queue.put_nowait(m) def run(self): while True: m = self.queue.get() if m is Terminate: break else: print("Received