What is the use of PYTHONUNBUFFERED in docker file?

DjangoDockerDockerfile

Django Problem Overview


I was watching a tutorial to dockerize my django application. I did not understand why we use PYTHONUNBUFFERED as environment variable in DockerFile.

Can you please help?

Django Solutions


Solution 1 - Django

Setting PYTHONUNBUFFERED to a non empty value ensures that the python output is sent straight to terminal (e.g. your container log) without being first buffered and that you can see the output of your application (e.g. django logs) in real time.

This also ensures that no partial output is held in a buffer somewhere and never written in case the python application crashes.

References:

Solution 2 - Django

PYTHONUNBUFFERED non empty value force the stdout and stderr streams to be unbuffered. This option has no effect on the stdin stream

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMayankBudhirajaView Question on Stackoverflow
Solution 1 - DjangoZeitounatorView Answer on Stackoverflow
Solution 2 - DjangoShreeyansh JainView Answer on Stackoverflow