[Fixed]-If I send a python 'Signal' object from a function, what should the "sender" argument be?

14👍

The django.dispatch.Dispatcher source simply says it should be

"...[t]he sender of the signal. Either a specific object or None."

which then ties in with the receiver via connect(), for which the sender’s significance is:

"The sender to which the receiver should respond. Must either be
 of type Signal, or None to receive events from any sender"

which, I admit, isn’t particularly clear, but in your case, I would say to use sender=None because there’s nothing concrete to hook to, as the request is transient.

0👍

A function is an object in Python, so you can just set the sender to be a reference your function, like this:

def my_func():
    my_signal.send(sender=my_func, my_arg="Hello")

Leave a comment