我的代码使用ThreadPoolExecutor来处理多个任务。主要要求之一是它无限期地执行。这是我当前的实现:
def process_something():
with ThreadPoolExecutor(max_workers=MAX_WORKERS1) as executor1:
with ThreadPoolExecutor(max_workers=MAX_WORKERS2) as executor2:
while True:
func1_returns = executor1.map(func1, arg1)
func2_returns = executor2.map(func2, arg2)
# code for processing func returns
time.sleep(1)
有没有更好的方法来实现这一点?由于执行器驻留在无限循环中,这是否可能是内存泄漏
线程池已经有多个线程要使用。您不需要创建多个池
线程池中不应存在任何内存泄漏。当
with
语句完成时,线程将被垃圾收集相关问题 更多 >
编程相关推荐