Is there any disadvantage in using PYTHONDONTWRITEBYTECODE in Docker?
Question:
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?
Answers:
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.
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?
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.