Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.03k stars 1.71k forks source link

[REQUEST] `progress.Progress` working with `async` code #3501

Open jamesbraza opened 3 days ago

jamesbraza commented 3 days ago

How would you improve Rich?

As of rich==13.8.1, it looks like Progress centers on a threading.RLock for thread safety. This is good for multithreading users.

Much of the Python community these days uses async (using asyncio or trio) code. threading.Lock/RLock are suboptimal for async code because they block all concurrent code in an event loop.

It would be nice to:

What problem does it solve for you?

Efficient asyncio code that uses rich for a progress bar

willmcgugan commented 2 days ago

AFAIK there are no issues with using progress in an async app.

The locks are there to synchronize with a thread that performs updates, and other threads launched by the dev. If they block, it is for microseconds, during which the cpu is 100% utilized and the async loop wouldn't be able to switch anyway.

In other words, the way Rich uses threading locks its no less optimal that any code between await keywords in an async app.