我有一些 python 代码目前通过许多线程并行执行计算来执行昂贵的计算。在给定的时间段内,许多线程被动态创建和启动,它们共享相同的代码,这些代码在线程的 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