Saturday, September 23, 2017

Re: best practices for location of start up code

On Sat, Sep 23, 2017 at 2:39 PM, Larry Martell <larry.martell@gmail.com> wrote:
> On Sat, Sep 23, 2017 at 1:34 PM, James Schneider
> <jrschneider83@gmail.com> wrote:
>>
>>
>> On Sep 22, 2017 2:58 PM, "Larry Martell" <larry.martell@gmail.com> wrote:
>>
>> We have some code we want to run 1 time when our django app is
>> started. What is the best place for this? I tried putting it in my
>> app's config function, but from there I get:
>>
>> *** AppRegistryNotReady: Apps aren't loaded yet.
>>
>>
>> Once as in only when the app is initially deployed, or once every time the
>> web server process is started?
>>
>> Note that if you place code to run every time the web process is started,
>> that it will run for every process, and most web servers spawn multiple
>> processes.
>
> I'm looking to run it once when the web server is started (not each
> time another process of the web server is started)

I am using nginx and uwsgi. I tried experimenting with Antonis
Christofides suggestion of using AppConfig.ready(). That seems to get
called just once when I start (or restart uwsgi). I tried many
connections to the server from different browsers and computers, but
still that was only called once. Is that something I can count on?

Note, when running the devel django server it was called twice at
start up, but when the 'real' server it was only called once. Anyone
know why I got the 2 calls here?

--
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+unsubscribe@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/CACwCsY4VDKy2H2-znVSJWG-a0rG%3DMQ8KxhvAnyLHtJPXdze1_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment