rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Support concurrent.futures? #100

Closed wcmiracle closed 3 years ago

wcmiracle commented 3 years ago

i want to ues

import multiprocessing from concurrent.futures import ProcessPoolExecutor

support it?

rsalmei commented 3 years ago

Hello again.

Sure it supports! But only one bar can be visible in the screen, that's the only limitation. Here is an example: asd

The code (save in a file.py and run python file.py):

from concurrent.futures import ProcessPoolExecutor, as_completed
from alive_progress import alive_bar
import time, random

def process(work):
     time.sleep(random.random())
     return work

if __name__ == '__main__':
    workables = [x for x in range(20)]

    with alive_bar(len(workables)) as bar:
        with ProcessPoolExecutor(max_workers=3) as pool:
            futures = [pool.submit(process, work) for work in workables]
            for future in as_completed(futures):
                print('work done:', future.result())
                bar()
    print('Ok! Everything done.\n')
wcmiracle commented 3 years ago

Thank you very much for the example, it will help others.

rsalmei commented 3 years ago

You're welcome man.