Skip to content

Doesn't work with docker-compose #771

Description

@justin-pierce
import time
from tqdm import tqdm

for i in tqdm(range(50), desc='debug'):
    time.sleep(0.1)

Then in terminal I see nothing until the loop has finished, and it just prints:

debug: 100% 50/50 [00:05<00:00, 9.81it/s]

My docker compose file has tty: true and os.isatty(sys.stdout.fileno()) returns true

Activity

  1. casperdcl commented on Jul 6, 2019

    @casperdcl
    SponsorMember

    Interesting. We provide a docker image
    which seems to work fine for its intended use in CLI pipe mode.

    What version of python are you using?

  2. justin-pierce commented on Jul 6, 2019

    @justin-pierce
    Author

    Image: FROM python:3.6

    Which is running 3.6.6

    Have tried it on two different computers and in both MacOS Terminal and VS Code Terminal.

  3. self-assigned this
    on Jul 7, 2019
  4. sepbot commented on Jul 12, 2019

    @sepbot

    The problem is not with Docker itself, but Docker Compose.

    To reproduce the problem, you need to first write a docker-compose.yaml file for your Docker service. Then bring up everything up by running docker-compose up -d and then following the logs by running docker-compose logs -f (or just run without -d, it will run in foreground I believe). If you follow these steps, you will find that the tqdm log line will not get outputted until a newline has been fed to stdout of that particular container after the loop has finished.

    The problem is not present if you just use Docker itself with the --tty flag.

  5. casperdcl commented on Jul 12, 2019

    @casperdcl
    SponsorMember

    thanks @sepbot - is this something that's been reported on the docker-compose repo?

  6. added
    invalid ⛔Not-an-issue or upstream (not-our-issue)
    and removed on Jul 12, 2019
  7. aneeshvartakavi commented on Sep 17, 2019

    @aneeshvartakavi

    I'm running into the same issue, are there any known workarounds or fixes for getting tqdm to work in docker compose?

  8. changed the title [-]Doesn't work in Docker? [/-] [+]Doesn't work with docker-compose[/+] on Sep 17, 2019
  9. shahidammer commented on Oct 18, 2019

    @shahidammer

    Did anyone manage to get the progress bar in the docker-compose. Any workaround?

  10. sepbot commented on Oct 19, 2019

    @sepbot

    Use docker-compose run instead of docker-compose up and tty: true in your service config

  11. waydegilliam commented on Jul 6, 2020

    @waydegilliam

    Use docker-compose run instead of docker-compose up and tty: true in your service config

    Just using docker-compose run in my compose yml worked for me (tty: true made no noticeable difference).

  12. sepbot commented on Jul 6, 2020

    @sepbot

    Use docker-compose run instead of docker-compose up and tty: true in your service config

    Just using docker-compose run in my compose yml worked for me (tty: true made no noticeable difference).

    You're right, docker-compose run allocates a TTY by default. Didn't know that at the time.

  13. added this to the v5.0.0 milestone on Jul 7, 2020
  14. added
    question/docs ‽Documentation clarification candidate
    and removed
    help wanted 🙏We need you (discussion or implementation)
    on Jul 7, 2020
  15. added 2 commits that reference this issue on Jul 19, 2020
    f115558
    a6c88d4
  16. Ghost---Shadow commented on Jul 6, 2022

    @Ghost---Shadow

    This workaround works fine too. For those who want to keep using docker compose up

    it = tqdm(total=len(arr))
    for e in arr:
      it.update(1)
      print(it)
  17. YuchiSu-Rin commented on Mar 19, 2024

    @YuchiSu-Rin

    This command can help if you are running in detach mode:

    docker compose up -d
    docker attach --sig-proxy=false [container-name]

    https://docs.docker.com/reference/cli/docker/container/attach/

    You must set tty: true to the service.

  18. ScrambledRK commented on Jun 23, 2024

    @ScrambledRK

    This discussion/thread was a true saver! I would never have guessed that its a docker-compose issue related to some missing newline. Although the issue is closed, I'd still like to contribute a little bit back with my workaround.

    from tqdm import tqdm
    
    tqdm_is_server = True  # somehow decide (e.g. check for tty)
    tqdm_disable = False  # server has no tty, but we use tqdm anyway
    
    
    class ServerTqdm(tqdm):
        def update(self, n=1):
            result = super().update(n)
    
            if result and tqdm_is_server:
                print(f"{self}\n")
    
            return result
    
        def display(self, msg=None, pos=None):
            if not tqdm_is_server:
                return super().display(msg, pos)
            return True
    
    
    for foo in ServerTqdm(range(0, 10), disable=tqdm_disable):
        print(foo)

    Based on Ghost---Shadow workaround and sepbot insight!
    Thank you two!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

invalid ⛔Not-an-issue or upstream (not-our-issue)question/docs ‽Documentation clarification candidateto-merge ↰Imminent

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions