Is there any disadvantage in using PYTHONDONTWRITEBYTECODE in Docker?
25 Mar 2023, 07:05 UTC
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
29 Mar 2023, 19:05 UTC
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.
26 Mar 2023, 19:05 UTC
28 Mar 2023, 07:05 UTC