swansonk14 / p_tqdm

Parallel processing with progress bars
MIT License
457 stars 44 forks source link

Allow overriding tqdm function used #45

Closed bridgerdier closed 2 years ago

bridgerdier commented 2 years ago

Added parameter to override tqdm to allow using p_tqdm with GUI progress bars.

tqdm flavors exist for tkinter and matplotlib, the following template could be used to feed progress bar values to any GUI toolkit:

class TqdmWrapper(tqdm.tqdm):
    def __init__(self, iterable, **kwargs):
        super().__init__(iterable=iterable, **kwargs)

    def display(self, msg=None, pos=None):
        print(self.format_dict)  # do something with self.format_dict['n']

Example for using with p_imap: iterator = p_tqdm.p_imap(add, ['1', '2', '3'], ['a', 'b', 'c'], tqdm=TqdmWrapper)

swansonk14 commented 2 years ago

This looks great, thank you @bridgerdier!