I need to execute some code when devserver is started.
At the moment I just place the code into models.py inside one of my applications.
This solution has a side effect: the code is executed when other managements commands are used, and I'd like to avoid it.
Updated: This will be a part of distributable application. I don't want users (developers actually) to run any additional commands. They should be able to use the runserver command only. I also don't want to override runserver command with my own implementation.
Updated: My models.py looks like this:
from django.conf import settings
if settings.DEBUG: # I actually use another setting here, but it does not matter
run_my_code_in_a_daemon_thread()
I don't have any actual models in this file. So, my code is executed only once: when Django scans all applications from INSTALLED_APPS and imports their models.py.