python怎么控制速度_如何控制python的ThreadPoolExecutor的吞吐量速度?

我使用python的concurrent.futuresThreadPoolExecutor启动异步任务。

按照this方法,我使用tqdm进度条监视异步调用的进度。在

我的代码如下所示:with concurrent.futures.ThreadPoolExecutor(max_workers = n_jobs) as executor:

future_to_url = {executor.submit(target_function, URL): URL for URL in URL_list}

kwargs = {'total': len(future_to_url), # For tqdm

'unit': 'URL', # For tqdm

'unit_scale': True, # For tqdm

'leave': False, # For tqdm

'miniters': 50, # For tqdm

'desc': 'Scraping Progress'}

for future in tqdm(concurrent.futures.as_completed(future_to_url), **kwargs):

URL = future_to_url[future]

try:

data = future.result() # Concurrent calls

except Exception as exc:

error_handling() # Handle errors

else:

result_handling() # Handle non-errors

控制台输出如下所示:

^{pr2}$

我知道我可以设置一个URL队列并控制其大小,如here所述。在

然而,我不知道如何控制吞吐量速度本身。假设我希望不超过6个URL/秒。这能用别的方法存档吗时间。睡觉(n) 在上面的例子中是target_function()?在

如何有效地控制python的ThreadPoolExecutor的吞吐量速度?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值