0

I have two Python files, server.py and capture.py. Both are initiated in docker-compose.local.yaml:

  server:
    build: ./app
    depends_on:
      - init
    ports:
      - 5000:5000
    command: ['server.py', '--url', 'redis://redisedge:6379']
  capture:
    build: ./app
    depends_on:
      - init
    command: ['capture.py', '--url', 'redis://redisedge:6379', 'data/walking.mp4']

In addition, server.py imports capture.py, though it does not reference capture.py anywhere else.

When I run docker-compose up, print statements in server.py show up in the terminal, but print statements in capture.py do not. I know that capture.py is running, because video output from the code is showing up in the appropriate port of my localhost. How can I get capture.py to print in terminal?

Boris K
  • 3,442
  • 9
  • 48
  • 87
  • it's difficult to say without knowing the contents of your files. Some things I would test: 1) is `capture.py` actually printing statements (replace its contents with `print("hello world")` to be sure) 2) run a bash session instead of `capture.py`, then drop into the docker container to try to run `capture.py` manually and verify output, things like that – anon01 May 04 '21 at 15:53
  • Does your Dockerfile set the `PYTHONUNBUFFERED` environment variable? (See [Python app does not print anything when running detached in docker](https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker).) – David Maze May 04 '21 at 17:13

1 Answers1

0

Passing a port to capture.py fixed it:

capture:
    build: ./app
    depends_on:
      - init
    ports:
      - 5001:5001
    command: ['capture.py', '--url', 'redis://redisedge:6379', 'data/walking.mp4']
Boris K
  • 3,442
  • 9
  • 48
  • 87