我有一些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