What is about PYTHONUNBUFFERED environment variable

You can view the output of your application (for example, django logs) in real time by setting PYTHONUNBUFFERED to a non-empty value other than 0, which will cause the python output, i.e. the stdout and stderr streams, to be sent directly to terminal (for example, your container log) without being first buffered.

1
2
3
4
FROM python:3.9-alpine3.13
LABEL maintainer="yakshaving.eu"

ENV PYTHONUNBUFFERED 1

Settings PYTHONUNBUFFERED to 1 prevents any unwritten partial output from being held in a buffer in the event that the python application terminates unexpectedly.

updatedupdated2024-01-172024-01-17