从内部线程杀死python线程的方法?

时间:2012-06-28 03:10:46

标签: python multithreading

我有一些python代码,目前通过许多线程并行执行计算来执行昂贵的计算。对于给定的时间段,许多线程被创建并在运行时启动,这些线程共享相同的代码,该代码在线程的run方法中明确声明。我的问题是如何在其run方法结束时停止/终止一个线程? (运行只调用一次)我需要这样做才能为下一批计算创建更多线程。

#Example

class someThread(threading.Thread):
    def __init__(self):
        #some init code
    def run(self):

        #Explicitly Stated Code without constant loops

        #Something performed to stop/kill this thread

1 个答案:

答案 0 :(得分:2)

您需要发出工作线程完成的主线程信号,然后在线程上调用join