import logging import multiprocessing import time def run_process1(queue: multiprocessing.Queue): while True: try: queue.put_nowait("process1") time.sleep(1) except Exception as e: logging.exception(e) def run_process2(queue: multiprocessing.Queue): while True: try: queue.put_nowait("process2") time.sleep(1) except Exception as e: logging.exception(e) def run_process3(queue: multiprocessing.Queue): while True: try: print(queue.get()) time.sleep(0.001) except Exception as e: logging.exception(e) if __name__ == "__main__": q = multiprocessing.Queue(maxsize=1024) while True: try: val = q.get_nowait() print(val) except: time.sleep(0.005) q.put_nowait("123123") print("出错") if __name__ == "__main__1": q = multiprocessing.Queue(maxsize=1024) p1 = multiprocessing.Process(target=run_process1, args=(q,)) p2 = multiprocessing.Process(target=run_process2, args=(q,)) p3 = multiprocessing.Process(target=run_process3, args=(q,)) p1.start() p2.start() p3.start() while True: time.sleep(0.1)