I've got a project based on django, that wraps some custom code.
During import, this code is loading some heavy file to be executed. I need to check whether imports are executed under "runserver command" or not. This way I can prevent loading heavy files during django installation.
How can I check if code is executed under runserver command?
Edit/UPDATE:
Unlike this question: How can I tell whether my Django application is running on development server or not?, I don't need to know whether the server is in debug or production mode.
I need to "discriminate" some "imports" based on whether the command below
python manage.py <COMMAND>
is runserver or not, regardless of whether it's debug or production mode.
MY_VAR=1 python manage.py runserver, then you can usesys.environ('MY_VAR) == '1'?imported, move the actual loading and computation inside some sort of function that you can call as needed. This will also be a problem for you in scenarios like unit testing, where you need the code available and may or may not want the expensive object load.runserverand/or doing conditional work based on that result, for example this one.