👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
To make my code more "pythonic" and faster, I use "multiprocessing" and a map function to send it a) the function and b) the range of iterations.
The implanted solution (i.e., call tqdm directly on the range tqdm.tqdm(range(0, 30)) does not work with multiprocessing (as formulated in the code below).
The progress bar is displayed from 0 to 100% (when python reads the code?) but it does not indicate the actual progress of the map function.
How to display a progress bar that indicates at which step the "map" function is ?
from multiprocessing import Pool
import tqdm
import time
def _foo(my_number):
square = my_number * my_number
time.sleep(1)
return square
if __name__ == "__main__":
p = Pool(2)
r = p.map(_foo, tqdm.tqdm(range(0, 30)))
p.close()
p.join()
Any help or suggestions are welcome...
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Multiprocessing : use tqdm to display a progress bar, check other __main__ Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Multiprocessing : use tqdm to display a progress bar
- Deutsch Multiprocessing : use tqdm to display a progress bar
- Français Multiprocessing : use tqdm to display a progress bar
- Español Multiprocessing : use tqdm to display a progress bar
- Türk Multiprocessing : use tqdm to display a progress bar
- Русский Multiprocessing : use tqdm to display a progress bar
- Português Multiprocessing : use tqdm to display a progress bar
- Polski Multiprocessing : use tqdm to display a progress bar
- Nederlandse Multiprocessing : use tqdm to display a progress bar
- 中文 Multiprocessing : use tqdm to display a progress bar
- 한국어 Multiprocessing : use tqdm to display a progress bar
- 日本語 Multiprocessing : use tqdm to display a progress bar
- हिन्दी Multiprocessing : use tqdm to display a progress bar
Vigrinia | 2023-03-26
Thanks for explaining! I was stuck with Multiprocessing : use tqdm to display a progress bar for some hours, finally got it done 🤗. I am just not quite sure it is the best method
California | 2023-03-26
Simply put and clear. Thank you for sharing. Multiprocessing : use tqdm to display a progress bar and other issues with os Python module was always my weak point 😁. Checked yesterday, it works!
London | 2023-03-26
Simply put and clear. Thank you for sharing. Multiprocessing : use tqdm to display a progress bar and other issues with SPL PHP module was always my weak point 😁. I am just not quite sure it is the best method