On 17 avr. 2010, at 16:37, anentropic <p...@blues.co.nz> wrote:
in the docs there is this paragraph:

"Note also that Django stores signal handlers as weak references by
default, so if your handler is a local function, it may be garbage
collected. To prevent this, pass weak=False when you call the signal ’s
connect()."

Can someone please explain to me what it means?
Python has automatic memory management. As long as at least one accessible reference to an object exists, the garbage collector won't destroy it. The point of a weakref is to be able to access the object without blocking the gc, so if the only references to an object are weak it *will* be garbage collected.

what's a "local function" in this sense?  a function in the same file
as the signal_name.connect(...) call?

I believe it would be a function from a local scope: a function created within another function or a method. At the module level the module itself will keep a reference to your handler, but if that's not the case (you have an event handler generating function for instance) the connect call might be the only one with a reference to the handler, and by default it will not prevent the GC from collection the handler.

what is the rationale for the weak reference behavior, presumably it's
desirable most of the time?
Simpler cleanup I'd guess.
--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to