Thank you Russell for your response. That confirms what I was thinking. I am going to use a queue.
On Thu, Oct 23, 2014 at 6:10 PM, Russell Keith-Magee < [email protected]> wrote: > HI Michael, > > There's a problem here - Web apps don't have a lifecycle like this. The > only part of the app lifecycle that can be relied upon is the > request-response cycle - someone makes a response, which will eventually be > returned as a response. Outside of that internal lifecycle, not much can be > guaranteed. A process will have to start in order to service a request (and > there are ways to hook into that), but there are no guarantees that this > process will last for 1 request, 10 or 10000. And there isn't a coordinated > shutdown of the web process - the web server may choose to shut down a web > worker at any time. > > If you're using a queue to perform some sort of external processing, then > that queue should be stored *outside* the web app itself. This means using > a message queue (like RabbitMQ), or a service that provides an analogous > interface (like RQ, layered over Redis). That way, a short lived web > request can push something onto the queue, and then exit immediately. The > web request doesn't need to worry about the lifecycle of the queue - it > just uses the queue as a service. > > In short - you need to stop thinking of the web server as a "program" with > a startup, shutdown, and predictable lifecycle, and move to thinking about > it as "a function floating in space that can be invoked" - because, in > practice, that's what it is. If you've got anything long lived, it needs to > live outside the web process. > > Yours, > Russ Magee %-) > > On Fri, Oct 24, 2014 at 5:18 AM, Michael <[email protected]> > wrote: > >> Hi, >> >> How to detect that the django app is stopping? >> >> I use some librairies that use a queue (queue.Queue) to store the data >> that will be sent in batch. >> They provide a flush method to flush at the end of the program to make >> sure there’s nothing left in the queue. >> >> But where could I call the flush method in django? >> >> Thanks >> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/ddecba43-49b3-493c-ad35-83d02758f95f%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/ddecba43-49b3-493c-ad35-83d02758f95f%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 a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/R13mmDcxYRM/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAJxq848W3m_OkRU9v29bN_AfX%3DoE_0qoh79zv_17sjQ2CSyUPg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAJxq848W3m_OkRU9v29bN_AfX%3DoE_0qoh79zv_17sjQ2CSyUPg%40mail.gmail.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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALa-rBwA-4Q6GXUW9gZ0kdZinStco%2B-A%2BH_fW3H5EjpOgAL9eg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

