pyc
files have been cause of grief in past , have seen few posts preventing python generating them. run script clean them after code changes ensure fresh ones generated easier disable them in general. there side effects disabling them in our production environment maybe not aware of? downsides of doing this?
the real issue experience files out of date causing import errors , difficult debug after massive refactor. once realizing pyc problem easy enough fix, run script realization come 30 minutes down road of debugging.
disabling writing , use of compiled bytecode comes performance cost @ startup -- python code loaded memory when process spawns, , non-.pyc/.pyo files means interpreter forced parse every imported file on startup. if you're removing .pyc , .pyo files code directory , imports, you're forcing version of already.
i'm curious they've caused grief in past (are disabling modified times on filesystem?) if .py
file newer .pyc
file, python interpreter (at least in common implementations, including cpython), re-compile source, that's not important scope of question.
if you're importing behind function, e.g.:
def my_database_call(budget_id): import some_expensive_module_to_import some_orm(...).get(budget_id)
that import cost won't incurred until function called (and perhaps, every subsequent time well). not markedly different if allow bytecode (.pyc
or "optimized" .pyo
files), @ least in case, you're paying import/parse/compile price once.
in case brought in comments, if you're "shelling out" os call python script, , not allowing bytecode written in call, every call incurs compilation price.