Hello, I am still new to Django, so I apologize if this seems like a silly 
question. I've not been able to find what I need on Google, StackOverflow, 
or the Django Docs. 

I am using Django 2.0.5.

I understand that the correct way to run startup code is to subclass 
AppConfig and override ready(). I also understand that Django launches two 
separate instances of the application--one to check the models, and the 
other to launch the server--on separate processes. The official 
recommendation to prevent startup code from being run more than once is to 
implement a flag--which can't work if there are multiple instances of the 
application being created. The docs also say that ready() will be re-called 
only rarely; but this doesn't help at all if all of the instances are 
calling ready() only once. 

I have found the manage.py runserver --noreload command, but this won't be 
enough to prevent multiple instances on a production server. What can I do 
to enforce one and only one instance of my application being run at a time? 

If it helps, here is the reason I need to override this multi-instantiation 
behavior: my application launches a multiprocessing.Process at startup to 
monitor and run background tasks. Having more than one background Process 
running at once is going to wreak havoc on the application. I've looked at 
other options to accomplish similar purposes, but those would all be 
instantiated multiple times, also. 

Any suggestions?

Thank you,
Heather

-- 
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/6d8729fe-18c4-4e53-8479-c2b9dd178b89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to