1 q = queue.Queue() 2 3 def producer(task): 4 q.put(task) 5 6 7 def consumer(): 8 while True: 9 task = q.get() 10 p = multiprocessing.Process(target=cli.start, args=task) 11 p.start() 12 p.join() # 进程堵塞直到结束 13 p1 = multiprocessing.Process(target=fortify_engine.start, args=task) 14 p1.start() 15 p1.join(1200) # 进程堵塞超时时间设置 16 if p1.is_alive(): 17 p1.terminate() # 关闭进程 18 print(task,"Process Timeout, be Terminated !!!") 19 p1.join() # 处理关闭后形成僵尸进程的现象 20 q.task_done() 21 22 threads = [] 23 for i in range(3): 24 threads.append(threading.Thread(target=consumer, args=())) 25 26 for i in threads: 27 i.setDaemon(daemonic=True) 28 i.start()