0

当一个线程完成时,有没有办法终止 ThreadPoolExecutor 和整个 python 脚本?

我有 2 个生产者线程和一个消费者线程。一旦用户类型退出,消费者线程就会通过返回“Exiting!”终止。

我研究过使用 .shutdown() 但它不会终止线程,我想终止所有线程并退出 python 脚本。

    with concurrent.futures.ThreadPoolExecutor() as executor:
        # submit once and returns a future object

        q1 = executor.submit(a,q) # consumer thread
        q2 = executor.submit(b, q) # producer thread
        q3 = executor.submit(c, q) # producer thread
        
       
        if q1.done:
           print(q1.result())
           # STOP all the threads since user typed exit and consumer
           # return "Exiting!"
           #END the program safely 
           # executor.shutdown dosn't work
4

0 回答 0