我想监控不同进程的多个工作人员的进度。对于每个子进程,我都有自己的进度条,但它不能与ProcessPoolExecutor执行程序正常工作。
def main():
with futures.ProcessPoolExecutor(max_workers=PROCESSES) as executor:
fut_to_num = {}
for i in range(PROCESSES):
fut = executor.submit(execute_many_threads, i)
fut_to_num[fut] = i
for future in futures.as_completed(fut_to_num):
r = future.result()
# print('{} returned {}'.format(fut_to_num[future], r))
print('\nDone!\n')
def execute_many_threads(n_pool=0):
with futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
for i in range(THREADS):
executor.submit(execute_thread, n_pool, i)
return n_pool+1
def execute_thread(n_pool=0, n_thread=0):
s = random.randint(1, 5)
thread_num = n_pool*(PROCESSES-1) + n_thread
progress = tqdm.tqdm(
desc='#{:02d}'.format(thread_num),
position=thread_num,
total=10*s,
leave=False,
)
# print('Executing {}: {}...'.format(thread_num, s))
for i in range(s): …Run Code Online (Sandbox Code Playgroud) python concurrent.futures python-multiprocessing tqdm process-pool
我正在使用 tqdm 和 requests 来管理 Python 中的文件下载。但是我不知道如何使 tqdm 以人类可读的格式(即以 MB/s 为单位)显示进度条。
这是我的代码
import requests
import os
from tqdm import tqdm
def download_file(url, local_path="./"):
local_filename = url.split('/')[-1]
path = local_path + local_filename
r = requests.get(url, stream=True)
total_size = int(r.headers.get('content-length', 0))
chunk_size = 32*1024
with open(local_filename, 'wb') as f:
# 1KB = 1024 bytes
for chunk in tqdm(r.iter_content(chunk_size), total=total_size, unit_scale=True,
unit_divisor=1024):
if chunk:
f.write(chunk)
return path
weightLink = "https://pjreddie.com/media/files/yolov3.weights"
weigthPath = r"/PyTorch-YOLOv3/weights/"
weightLink = "https://pjreddie.com/media/files/yolov3.weights"
download_file(weightLink, weigthPath)
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,下载大小的进度是错误的,我在 中看到下载速度it/s。我希望所有内容都以MB/s …
是否可以设置描述tqdm是否可以在 for 循环之外
一个简单的例子:
with tqdm(range(100), desc='processing') as pbar:
x = 0
for i in pbar:
x += i
y = x ** 2
# 3. set description of pbar 'y = {}'.format(y)'
Run Code Online (Sandbox Code Playgroud)
我应该用什么来代替3.?
编辑:更准确地说,我想y在完全执行 for 循环后进行计算,然后我想y在进度条描述中记录该值(替换'processing'描述)。
我在笔记本中使用 tqdm (from tqdm.auto import tqdm),输出很好且正确,但是当在终端中运行脚本时使用同一行时,我会阻塞多行输出。tqdm 有什么方法可以区分笔记本输出和终端输出吗?
我想将数据从大型csv文件迁移到sqlite3数据库.
我使用pandas在Python 3.5上的代码:
con = sqlite3.connect(DB_FILENAME)
df = pd.read_csv(MLS_FULLPATH)
df.to_sql(con=con, name="MLS", if_exists="replace", index=False)
Run Code Online (Sandbox Code Playgroud)
是否可以打印执行to_sql方法的当前状态(进度条)?
我查看了关于tqdm的文章,但没有找到如何做到这一点.
在我的 python 项目中,我使用tqdm模块来显示进度条。\n我想在进度条之前的行上打印一条持久消息。
该set_description方法在同一行上打印消息,同时tqdm.write创建一个新行。
使用set_description
$ python pbar.py\n{Task_1 message} 3%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 ]
有可能实现这一点
\n\n$ python pbar.py\n{Task_1 message} \n3%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 ]
编辑:
\n\nfrom tqdm import tqdm\n\npbar = tqdm(m_list)\nfor item in m_list:\n # Do work\n pbar.update(1)\npbar.close()\nRun Code Online (Sandbox Code Playgroud)\n 我想progresser()针对一系列输入参数 ( ) 并行化任务 ( L)。每个任务的进度应通过终端中的单独进度条进行监控。我正在使用tqdm进度条包。以下代码在我的 Mac 上最多可运行 23 个进度条(L = list(range(23))及以下),但会产生从 开始的进度条的混乱跳跃L = list(range(24))。有谁知道如何解决这个问题?
from time import sleep
import random
from tqdm import tqdm
from multiprocessing import Pool, freeze_support, RLock
L = list(range(24)) # works until 23, breaks starting at 24
def progresser(n):
text = f'#{n}'
sampling_counts = 10
with tqdm(total=sampling_counts, desc=text, position=n+1) as pbar:
for i in range(sampling_counts):
sleep(random.uniform(0, 1))
pbar.update(1)
if __name__ == '__main__':
freeze_support()
p = Pool(processes=None, …Run Code Online (Sandbox Code Playgroud) 我在 Jupyter 笔记本中使用 tqdm 进行异步操作——我应该使用tqdm.notebook(我认为这能让我得到正确的小部件)还是tqdm.asyncio(这可能会让我得到正确的行为——items/sec calc 在我的使用中似乎关闭了) 。
我正在使用 Jupyter 小部件编写一个界面,用户在其中配置一堆设置,然后单击“运行”按钮。单击后,此按钮将调用另一个模块中实现的函数。该函数需要一些时间才能运行,因此我使用该包向其添加了一个进度条tqdm。不幸的是,当我单击“运行”时,此进度条现在显示在另一个终端中,而不是在单元格的输出中。有没有办法让条形图显示在同一单元格输出中?
是否可以将 tqdm 栏从
\n[Step 1]: 100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 109/109 [00:03<00:00, 32.46it/s]\nRun Code Online (Sandbox Code Playgroud)\n类似的东西
\n[Step 1]: 100%[==========================> ] 109/109 [00:03<00:00, 32.46it/s]\nRun Code Online (Sandbox Code Playgroud)\n tqdm ×10
python ×8
python-3.x ×2
terminal ×2
dataframe ×1
ipywidgets ×1
jupyter-lab ×1
logging ×1
pandas ×1
process-pool ×1
progress-bar ×1
sqlite ×1