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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to