Ticket #11441: patch11441-1.diff
File patch11441-1.diff, 5.5 KB (added by , 14 years ago) |
---|
-
django/dispatch/dispatcher.py
41 41 A function or an instance method which is to receive signals. 42 42 Receivers must be hashable objects. 43 43 44 if weak is True, then receiver must be weak-referencable (more44 If weak is True, then receiver must be weak-referencable (more 45 45 precisely saferef.safeRef() must be able to create a reference 46 46 to the receiver). 47 47 … … 52 52 dispatch_uid. 53 53 54 54 sender 55 The sender to which the receiver should respond Must either be55 The sender to which the receiver should respond. Must either be 56 56 of type Signal, or None to receive events from any sender. 57 57 58 58 weak 59 Whether to use weak references to the receiver By default, the59 Whether to use weak references to the receiver. By default, the 60 60 module will attempt to use weak references to the receiver 61 61 objects. If this parameter is false, then strong references will 62 62 be used. … … 170 170 Arguments: 171 171 172 172 sender 173 The sender of the signal Can be any python object (normally one173 The sender of the signal. Can be any python object (normally one 174 174 registered with a connect if you actually want something to 175 175 occur). 176 176 … … 182 182 Return a list of tuple pairs [(receiver, response), ... ]. May raise 183 183 DispatcherKeyError. 184 184 185 if any receiver raises an error (specifically any subclass of185 If any receiver raises an error (specifically any subclass of 186 186 Exception), the error instance is returned as the result for that 187 187 receiver. 188 188 """ -
docs/topics/signals.txt
141 141 the :doc:`built-in signal documentation </ref/signals>` for details of each 142 142 particular signal. 143 143 144 Additional signal connection options 145 ------------------------------------ 146 147 The complete signature for the signal ``connect()`` function is: 148 149 .. method:: Signal.connect(receiver, sender=None, weak=True, dispatch_uid=None) 150 151 The *receiver* and *sender* arguments have been described in detail above. The 152 two remaining arguments are optional, and are described here: 153 154 * *weak* - Django stores signal handlers as weak references by 155 default. Thus, if your receiver function is a local function, it may be 156 garbage collected. To prevent this, pass ``weak=False`` when you call the 157 signal's ``connect()`` function. 158 159 * *dispatch_uid* - In some circumstances, the module you are 160 connecting signals in may be imported multiple times. This can cause 161 your receiver function to be registered more than once, and thus called 162 multiples times for a single signal event. 163 164 If this behavior is problematic (for example, you may using signals to 165 send an e-mail whenever a model is saved), pass a unique identifier as the 166 ``dispatch_uid`` argument to identify your receiver function. This 167 identifier will usually be a string, although any hashable object will 168 suffice. The end result is that your receiver function will only be 169 bound to the signal for each unique *dispatch_uid* value. 170 144 171 Defining and sending signals 145 172 ============================ 146 173 … … 171 198 Sending signals 172 199 --------------- 173 200 201 There are two ways to send send signals in Django. 202 174 203 .. method:: Signal.send(sender, **kwargs) 175 204 176 To send a signal, call :meth:`Signal.send`. You must provide the ``sender`` argument, and may provide as many other keyword arguments as you like. 205 .. method:: Signal.send_robust(sender, **kwargs) 177 206 207 To send a signal, call either :meth:`Signal.send` or :meth:`Signal.send_robust`. 208 You must provide the ``sender`` argument, and may provide as many other keyword 209 arguments as you like. 210 178 211 For example, here's how sending our ``pizza_done`` signal might look: 179 212 180 213 .. code-block:: python … … 186 219 pizza_done.send(sender=self, toppings=toppings, size=size) 187 220 ... 188 221 222 Both ``send()`` and ``send_robust()`` return a list of tuple pairs 223 ``[(receiver, response), ... ]``, representing the list of called receiver 224 functions and their response values. 189 225 226 ``send()`` differs from ``send_robust()`` in how exceptions raised by receiver 227 functions are handled. ``send()`` does *not* catch any exceptions raised by 228 receivers; it simply allows errors to propagate. Thus not all receivers may 229 be notified of a signal in the face of an error. 230 231 ``send_robust()`` catches all errors derived from Python's ``Exception`` class, 232 and ensures all receivers are notified of the signal. If an error occurs, the 233 error instance is returned in the tuple pair for the receiver that raised the error. 234 235 Disconnecting signals 236 ===================== 237 238 .. method:: Signal.disconnect(receiver=None, sender=None, weak=True, dispatch_uid=None) 239 240 To disconnect a receiver from a signal, call :meth:`Signal.disconnect`. The 241 arguments are as described in `additional signal connection options`_. 242 243 The *receiver* argument indicates the registered receiver to disconnect. It may 244 be ``None`` if ``dispatch_uid`` is used to identify the receiver.