[ACCEPTED]-Is there a way to list Django signals?-django-signals
It's not really exposed in docs but Signal 3 is just a class that contains a list of 2 receivers which are called on event. You 1 can manually check this list:
from django.db.models.signals import *
for signal in [pre_save, pre_init, pre_delete, post_save, post_delete, post_init, post_syncdb]:
# print a List of connected listeners
print signal.receivers
There's a django app called django-debug-toolbar which adds 8 a little toolbar at the top of all django 7 served pages providing info related to the 6 backend of the page's rendering, such as 5 how many queries were executed, how much 4 time they each took, etc. It also prints 3 out signals. I don't use signals in my app, so 2 I have never used that feature, but it's 1 there.
I wrote little command that shows all signal 2 listeners: https://gist.github.com/1264102
You can modify it to show signals 1 only.
If you want to list only the connected receivers 6 for a specific signal on a specific model, you 5 can look at _live_receivers
. For instance, if you want 4 to list the connected post_save hooks for 3 a model named MyModel, you can do:
from django.db.models.signals import post_save
from models import MyModel
print(post_save._live_receivers(MyModel))
I found 2 this approach in the Django source code 1 by looking for how has_listeners
works: https://github.com/django/django/blob/3eb679a86956d9eedf24492f0002de002f7180f5/django/dispatch/dispatcher.py#L153
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.