Skip to content

Fail to set console option for rich progress bar #142

@zetxtech

Description

@zetxtech

Sorry for submitting so many issues.

I found that when using the rich progress bar, setting the console in the options causes the progress bar not to display:

import time
from mpire import WorkerPool
from rich.console import Console
from tqdm.rich import tqdm

console = Console(stderr=True)

def _job(_, i):
    time.sleep(0.5)
    return i

def main():
    results = {}
    with WorkerPool(n_jobs=32, use_worker_state=True) as pool:
        for i, r in enumerate(pool.imap_unordered(
            _job, 
            range(120), 
            progress_bar=True,
            progress_bar_style='rich',
            progress_bar_options={"options": {"console": console}},
        )):
            if r:
                results[i] = {"result": r}
    print(results)
    
def main_tqdm():
    results = {}
    for i in tqdm(range(1000), options={"console": console}):
        r = _job({}, i)
        if r:
            results[i] = {"result": r}
    print(results)

if __name__ == "__main__":
    main()

As you can see in main_tqdm, setting the console in the options works, but it is not working and causing the progress bar to disappear in progress_bar_options.

Why set the console? Because I have other logs that need to be displayed via console.print(). If the console is not set, it will cause the progress bar and logs to mix and jump around.

Thank you in advance for your answer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions