2

I've a python application in which I'm using print() method tho show text to a user. When I interact with this application manually using kubectl exec ... command I can see the output of prints.

However, when script is executed automatically on container startup with CMD python3 /src/my_app.py (last entry in Dockerfile) then, the prints are gone (not shown in kubectl logs). Ayn suggestin on how to fix it?

2 Answers 2

5

This is because stdout and stderr streams are buffered in Python.

You can set the Environment variable to PYTHONUNBUFFERED=1 or True

Also you could use -u option in your Dockerfile.

-u

Force the stdout and stderr streams to be unbuffered. This option has no effect on the stdin stream.

Changed in version 3.7: The text layer of the stdout and stderr streams now is unbuffered.

Sign up to request clarification or add additional context in comments.

Comments

3

It turned out to be a problem of python environment. Setting, these two environment variables PYTHONUNBUFFERED=1 and PYTHONIOENCODING=UTF-8 fixed the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.