Textualize/rich

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

jamesbraza opened this issue · 2 comments

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:

  • Support an async-equivalent of Progress
  • Document the thread-safety (and potential async safety) of Progress in the docs here

What problem does it solve for you?

Efficient asyncio code that uses rich for a progress bar

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.

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual