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?
Following are disadvantages associated with Docker: Containers don't run at bare-metal speeds. Containers consume resources more efficiently than virtual machines. But containers are still subject to performance overhead due to overlay networking, interfacing between containers and the host system and so on.
Docker is more limited and can run only on Linux, certain Windows servers and IBM mainframes if hosted on bare metal. For example, Docker runs natively only on bare-metal Windows servers running Windows Server 2016 or later.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With