Re: "things are ready" signal?

2008-10-02 Thread Malcolm Tredinnick


On Wed, 2008-10-01 at 23:04 +0200, Marc Fargas wrote:
> Hi there,
> 
> Staring at #8638 I'm trying to find a way to hook code to be run "just
> after Django is completelly loaded" and found no way ;(
> 
> The thing is, it's a really nice place to emit a signal if you want to
> do things "just after things are ready", but there's no signal for it.
> 
> And, as I found nowhere to hook the code for #8638 I have no idea of
> where such signal should be emitted from (or that code hooked).
> 
> So, would a signal there be useful? (no ticket filled yet) And, where
> can one hook code for that? :)

As pointed out elsewhere in the thread, your request is not very
well-defined. However, there is a more concrete idea in #5685 that has
some legs. Ben Slavin (__hawkeye__) and I have been discussing on and
off the need for something that basically runs after settings has been
loaded -- which is about as close as you can get to "before Django does
anything significant". The main usage for this is things like
registering cross-application signal handlers at the right time without
needing requirements like "this app must go after all other apps in the
list" (since as soon as you have two such apps, you cannot satisfy the
requirement). The other main usage I had in mind was for setting up
per-test changes that might be required.

That ticket is on my list of features to add, so now that we've branched
I can look at it again. It's not an entirely trivial patch, but I've
read it a couple of times in the past (and Ben and I worked on it
together at a sprint last year). I want to check we haven't missed
anything obvious now that a couple of months have gone by since I last
looked, but it should be ready and committed soon.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-02 Thread Ivan Sagalaev

Marc Fargas wrote:
> 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. 

For the record, there's a better (IMO) workaround: create an app with a 
models.py and put logic there. It will be loaded just at the end of 
everything when settings are ready.

Still, it's a workaround and a proper signal would be useful and its 
time is more or less obvious: after all apps in INSTALLED_APPS are loaded.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-02 Thread Marc Fargas

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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-01 Thread James Bennett

On Wed, Oct 1, 2008 at 4:04 PM, Marc Fargas <[EMAIL PROTECTED]> wrote:
> The thing is, it's a really nice place to emit a signal if you want to
> do things "just after things are ready", but there's no signal for it.

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)?

This is one of many problems with a "Django is ready" signal --
everybody's going to have a use case which demands a different
definition of what "ready" means.

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.

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).


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-01 Thread Thomas Guettler

Marc Fargas schrieb:
> Hi there,
>
> Staring at #8638 I'm trying to find a way to hook code to be run "just
> after Django is completelly loaded" and found no way ;(
>   
...
> So, would a signal there be useful?
I am missing this signal, too.

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-01 Thread Waylan Limberg

On Wed, Oct 1, 2008 at 5:04 PM, Marc Fargas <[EMAIL PROTECTED]> wrote:
>
>
> So, would a signal there be useful? (no ticket filled yet) And, where
> can one hook code for that? :)
>

I seem to recall this request being made from time to time. IIRC, it
always turned out that whoever asked didn't really want this, but
something else. Therefore, I don't believe anyone has provided a valid
use case for such a signal. I'd suggest searching the archives.



-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "things are ready" signal?

2008-10-01 Thread Collin Grady

On Wed, Oct 1, 2008 at 2:04 PM, Marc Fargas <[EMAIL PROTECTED]> wrote:
> So, would a signal there be useful? (no ticket filled yet) And, where
> can one hook code for that? :)

I don't think any such place exists, so there's nothing you can do for it.

-- 
Collin Grady

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---