Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to optimize the display of progress bar by python multi-process

Shulou Source: shulou.com Published: 2022-05-31 10:40:57 09月23日 Update

Today Xiaobian to share with you how to optimize the python multi-process display progress bar related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have some harvest after reading this article, let's learn about it together.

1. Using the imap method of the multiprocessing process pool, the function is applied to all elements of the iterable object in turn and sent to multiple processes.

2. With tqdm library, the overall execution progress of multi-process code can be displayed through progress bar.

examples

from multiprocessing import Poolfrom tqdm import tqdmimport mathimport numpy as np def func(x): return math.sin(x)+math.cos(x)with Pool(processes = 20) as pool: result = list(tqdm(pool.imap(func, np.linspace(0,2*math.pi,1000)), total=1000)) The above is "Python multi-process how to optimize the display progress bar" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Process progress knowledge article content different big code function element function can pass multiple most instance object that is whole method more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Huawei Apple macOS Shulou Tech Info