python - 在 if 语句中使用 tqdm 进度条
问题描述
其实我有这个代码:
#!/usr/bin/env python3
import sys
import requests
import random
from multiprocessing.dummy import Pool
from pathlib import Path
requests.urllib3.disable_warnings()
print ('Give name of txt file on _listeNDD directory (without.txt)'),
file = str(input())
if Path('_listeNDD/'+file+'.txt').is_file():
print ('--------------------------------------------------------')
print ("Found")
print ('--------------------------------------------------------')
print ('Choose name for the output list (without .txt)'),
nomRez = str(input())
filename = '_listeNDD/'+file+'.txt'
domains = [i.strip() for i in open(filename , mode='r').readlines()]
else:
print ('--------------------------------------------------------')
exit('No txt found with this name')
def check(domain):
try:
r = requests.get('https://'+domain+'/test', timeout=5, allow_redirects = False)
if "[core]" in r.text:
with open('_rez/'+nomRez+'.txt', "a+") as f:
print('https://'+domain+'/test', file=f)
except:pass
mp = Pool(100)
mp.map(check, domains)
mp.close()
mp.join()
exit('finished')
使用此代码,它打开目录“_listeNDD”上的文本文件,我在目录“_rez”上写入新的文本文件。显然它对于十个元素来说非常快,但是当它变得更大时,我想要一个进度条来知道我是否有时间煮咖啡。
我曾亲自尝试使用 github tqdm,但不幸的是,它为它所做的每项工作显示了一个进度条,而我只想要一个用于所有工作的进度条......
任何想法?谢谢
编辑:使用这篇文章,我没有成功
if __name__ == '__main__':
p = Pool(100)
r = p.map(check, tqdm.tqdm(range(0, 30)))
p.close()
p.join()
我没有足够高的 python 级别来掌握这一点,所以我可能将它严重集成到我的代码中。我还看到:
if __name__ == '__main__':
r = process_map(check, range(0, 30), max_workers=2)
解决方案
推荐阅读
- python - Python 的 exif 模块和 JPEG 元数据中的元音变音
- bash - 如何从 1 个 csv 文件中获取数据,并将其与另一个文件合并到 Bash 脚本中的特定列中?
- javascript - Vee validate v3 ValidationObserver 不与使用 v-for 添加的动态验证提供程序一起工作
- python - GSSAPI 错误:升级到 MacOs BigSur 后出现其他故障(参见文本(来自 KDC 的错误:PROCESS_TGS)
- python - 从一列中包含多个值的csv文件创建面积图
- powershell - Azure DevOps 如何运行 exe 数据库迁移
- javascript - CSS 和 JS 无法从引导程序加载到 html 中
- cmake - CMake安装目录文件而不保留完整目录顶部
- rust - 如何在 Rust 中正确处理来自 maxminddb::geoip2 的 AddressNotFound 错误?
- python - Python Selenium 身份验证代理