Sunday, June 20, 2010

Re: A Django project life cycle

On Jun 20, 10:07 pm, Sam Lai <samuel....@gmail.com> wrote:
> If you want to run a piece of code on receiving a view HTTP request,
> and a piece of code just before the response is sent to the user, look
> into Django middleware
> (http://docs.djangoproject.com/en/dev/topics/http/middleware/). That
> is what it is specifically designed to do.
>
> If instead you want to run a piece of code when Django starts up, and
> when it is killed, that would depend on how you are serving the page.
> Are you using Apache? With mod_python, or mod_wsgi?
>
> If you're using mod_wsgi (which you should), the mod_wsgi docs are
> quite useful, e.g.http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

Also read:

http://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode

Per request cleanup code can be done in Django, but in mod_wsgi at
least (not mod_python), one can use atexit module to register process
cleanup functions. Because processes can crash though, you shouldn't
rely on process exit code running.

As to start up, if you are careful and ensure that Django is properly
preloaded outside of request handling per WSGI script on my blog and
referenced else, then can trigger tasks to do on startup when WSGI
script loaded.

Graham

> Also, Django's signals functionality might be help too if middleware
> is not -http://docs.djangoproject.com/en/dev/ref/signals/#ref-signals
>
> On 20 June 2010 21:24, Sameer Rahmani <lxsam...@gmail.com> wrote:
>
>
>
> > i want to run a peace of code in the beginning of life cycle ( may be
> > in settings.py ) but i want to know about
> > number process and the codes that remain on memory ? olso i want to
> > run a peace of code in the ending part
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate