You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ThreadPoolExecutor map方法的状态监控与多线程性能验证问题

ThreadPoolExecutor.map 状态监控与效率验证问题

我遇到的问题和《Checking up on a concurrent.futures.ThreadPoolExecutor》高度相似,但存在关键差异:我没有使用executor.submit,而是因任务数量多变且可能较多,采用了map方法。相关代码如下:

with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
    list_of_chain_responses = list(executor.map(chain, question_list))
    print('pending:', executor._work_queue.qsize(), 'jobs')
    print('threads:', len(executor._threads))
    print()

我尝试了该问题中的解决方案,但显示pending任务数始终为0且仅打印一次,推测是因为打印操作要等整个question_list的任务都被异步提交给chain函数后才执行,完全看不到中间状态。

我的核心需求是验证该多线程方案是否提升了处理效率,以及提升幅度有多大。此前对比过有无线程的执行情况,但网络波动导致结果不准确;也尝试在chain函数中加入print("start")和print("end"),但明明处理了question_list中的多个任务,却只看到一次输出。

内容的提问来源于stack exchange,提问作者Rasputin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 10:14:51