I would like to make tqdm works when executed in a cloud env where logs are propagated as text to external services. I am mostly talking about Kubernetes here, but I guess it also apply to any other container orchestration tool.
Consider this simple snippet using tqdm 4.64:
import sys
from tqdm import tqdm
from time import sleep
for i in tqdm(range(10)):
sleep(5)
sys.stderr.write("\n")
When removing sys.stderr.write("\n") then the tqdm progress bar only display at the very end of the loop in one shot to 100%. It obviously defeats the purpose of the progress bar.
Adding sys.stderr.write("\n") trigger a log flush (or propagation) to wherever the logs are sent (Kubernetes console for example) and so the progress bar is displayed at regular interval.
This simple snippet is actually a workaround to make tqdm works with Kubernetes, but it does not reflect the complexity of a given stack where things like progress bar can be deeply nested into the codebase and so not "tunable" when executing a workload.
I have two questions here:
- Is there is actually another more "automatic" workaround than
sys.stderr.write("\n")?
- Would you be willing to add to
tqdm(range(10), ...) a new arg that can trigger this sys.stderr.write("\n") whenever the bar must be updated? We could eventually imagine auto-detecting (if possible) Kubernetes or simply setting a boolean flag.
- On this it seems important to me to add a new tqdm arg instead of a more complex solution since in a deeply nested codebase, tqdm args is often the only thing you have control on. Auto-detection would be even better, if that something easily doable (I can dig into this if needed).
I would like to make tqdm works when executed in a cloud env where logs are propagated as text to external services. I am mostly talking about Kubernetes here, but I guess it also apply to any other container orchestration tool.
Consider this simple snippet using tqdm 4.64:
When removing
sys.stderr.write("\n")then the tqdm progress bar only display at the very end of the loop in one shot to 100%. It obviously defeats the purpose of the progress bar.Adding
sys.stderr.write("\n")trigger a log flush (or propagation) to wherever the logs are sent (Kubernetes console for example) and so the progress bar is displayed at regular interval.This simple snippet is actually a workaround to make tqdm works with Kubernetes, but it does not reflect the complexity of a given stack where things like progress bar can be deeply nested into the codebase and so not "tunable" when executing a workload.
I have two questions here:
sys.stderr.write("\n")?tqdm(range(10), ...)a new arg that can trigger thissys.stderr.write("\n")whenever the bar must be updated? We could eventually imagine auto-detecting (if possible) Kubernetes or simply setting a boolean flag.