Hi,

On Thu, Oct 2, 2008 at 8:55 AM, James Bennett <[EMAIL PROTECTED]> wrote:
> Just after *what* is ready, precisely? After "import django" has
> succeeded? After settings have been imported? After model caches have
> been initialized? After a request handler has been instantiated (which
> we already sort of have a signal for)?

Or "Just before request handler or manage.py command handling" takes place.
"Ready" would mean "When django is imported, settings are ready, model
classes are ready".

> As it is, you have a signal which fires when we start processing an
> HTTP request, and that's what most people should look to since Django
> is, fundamentally, about cycles of HTTP request/HTTP response and so
> that's the most useful mindset to have.

Sure, but if you want to run a code that affects all requests (i.e.
"Replace the SMTP Connection class for all requests") you can't be
doing that *on every request*, the place to do so would be "just
before starting serving requests".

> Failing that, there are plenty of well-established Python idioms for
> "run this code once and only once the first time I'm imported", which
> covers the remainder of the use cases (or really stubborn people who
> want to act like Django is a desktop application instead of a web
> framework).

In the case of the ticket I mentioned it's not that easy, as you won't
import anything, you have a setting "DISABLE_EMAIL" which has to do
what the testsuite does now: Replace SMTP Connection class. So you
need to check this setting *after settings have been loaded*. The only
signal you can hook "after settings are loaded" are all fired more
than once (class_prepared, request_started, etc). There's no signal
that gets fired *once*.

So, if you need to hook something that need to run *once* after django
loads (at any level) you need to either monkey-patch or patch Django
itself. I would say to put a signal on every stage of the load process
but one just after settings are ready and one just before starting to
serve requests or handling manage.py commands would be a nice one.

-- 
http://www.marcfargas.com - will be finished someday.

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

Reply via email to