How to use rich progress bar with RichHandler and python's logging API? #969
-
Hi :) In our multiprocessing framework we use a logging queue and a Logging like this works fine. However, so far we could not figure out a way to also log for example rich's progress bar in a child process. Because right now we rely on the setup of calling e.g. Ideally, in case of specifying a stream handler like your Is there a way of accomplishing this? :) Thanks in advance for your support! Edit 1: Not equally important, but besides logging progress bars, is there maybe also a solution to log other rich specific features such as trees, tables, etc. via the Edit 2: For reference, our log forwarding approach described above follows the idea of the second example (using a listener thread instead of process) documented in the logging coocbook. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi @LarsHill You will need a mechanism to pass information from your workers to your main process. Either a pipe or a queue. Essentially what the QueueHandler is doing but for progress information. Logging wasn't really designed to work with anything other than text. Although you can format anything Rich can render in log format with the log method. Hope that helps. Will |
Beta Was this translation helpful? Give feedback.
-
Pretty much. If you are using a queue, your workers would call
You can convert Rich objects to text and log that, which is what tqdm is doing there.
That would help, but you would still have the issue of managing Progress bars, as there can be only one active at a time. |
Beta Was this translation helpful? Give feedback.
-
It's more that there is only one stdout. In order to get the progress bar updating at the bottom, Rich has to move the cursor around. If another process or other progress bar is also moving the cursor the visuals become garbled. |
Beta Was this translation helpful? Give feedback.
-
Don't quite follow, but you should aim for a single Progress instance in the main process, updated by information sent by the workers. Good luck! |
Beta Was this translation helpful? Give feedback.
Pretty much.
If you are using a queue, your workers would call
queue.put()
when they have progress to update. Your main process would receive these updates withqueue.get()
in a loop, and update the Progress bar accordingly.You can convert Rich objects to text and log that, which is what tqdm is doing there.