docker-py
docker-py copied to clipboard
tqdm output is only printed at the end
I am trying to run a python program using tqdm through the docker python sdk.
Here code to reproduce what I am talking about:
import docker
client = docker.from_env()
container = client.containers.run(
"tqdm/tqdm",
[
"-u",
"-c",
"""
import tqdm
import time
for r in tqdm.tqdm(range(100)):
time.sleep(0.1)
"""
],
entrypoint="python",
detach=True,
)
for line in container.logs(stream=True):
print(line.decode("utf-8").strip())
It only returns the status bar at the very end and doesn't continuously update it as expected.
I run this with Python 3.8.10 and docker sdk version 5.0.3 installed with pip install docker.
I filled an issue with tqdm (see https://github.com/tqdm/tqdm/issues/1304) first, but I suspect that this is actually some buffering issue in docker-py instead.
I also tried to run this with the tty=True enabled. In that case you run into https://github.com/docker/docker-py/issues/2913.
Is there a trick to make docker-py output right away?