docker / docker/docker-py

tqdm output is only printed at the end

Open
#2,996 0 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the container.logs(stream=True) path shown in the reproduction and compare its behavior with the tty=True case and the linked issue. Reproduce the example using Python 3.8.10 and docker SDK 5.0.3; done means streamed tqdm output is visible incrementally rather than only after the container finishes.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.