Hi, Wouldn't it be possible to use celery and tasks for this purpose? http://www.celeryproject.org/
You could have it running all the time and have a flag in the database for when the server is running? Regards, Andréas 2016-01-11 9:59 GMT+01:00 Tony Flury <anthony.fl...@btinternet.com>: > I have a small background task (executed by using threading.Timer) which I > want to start up when the server starts, but doesn't need to start when a > management command runs. > > The background task performs operations on the database, so relies on > importing the models etc. > > I have tried using the App.ready hook introduced in Django 1.7, which was > touted as correct way to do this, but the ready hook is executed during > management commands as well, and then the management command fails to exit > - due to the presence of the timer thread - and I don't want Management > commands to execute this code in anyway. > > What is the correct way to run code which uses the models and all the > wonderful Django stuff, and which is executed only when the server runs > (and not during a management command). > > Currently the only way I can run management command is to comment out my > timer start call, whenever I want to run management commands. This wont be > an option when it comes to needing to execute management commands on the > production server. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/7632c40e-0855-453d-95f9-cb2f552ddd22%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/7632c40e-0855-453d-95f9-cb2f552ddd22%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3DOuB5ocYg63QnJg52vTqj64BNUDPz_EcPCrpbasfo%3DTA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.