Is there any disadvantage in using PYTHONDONTWRITEBYTECODE in Docker?
Jan 14
In many Docker tutorials based on Python (such as: this one) they use the option PYTHONDONTWRITEBYTECODE in order to make Python avoid to write .pyc files on the import of source modules (This is equivalent to specifying the -B option).
What are the risks and advantages of setting this option up?
1 answer
Accepted answer · original discussion
Mar 22
When you run a single python process in the container, which does not spawn other python processes itself during its lifetime, then there is no "risk" in doing that.
Storing byte code on disk is used to compile python into byte code just upon the first invocation of a program and its dependent libraries to save that step upon the following invocations. In a container the process runs just once, therefore setting this option makes sense.
2 question comments
Use comments to ask for clarification. Post a solution as an answer.
Jan 14
Jan 14