想在项目中用上,就实习一下。
# coding:utf8 from django.dispatch import Signal from django.dispatch import receiver custom_signal = Signal() class Demo2: def __init__(): print "__init__" pass class Demo: def __init__(): print "__init__" pass def ak(): pass @receiver(custom_signal, sender=ak) def my_callback(sender, **more): print sender print more print "my callback called" @receiver(custom_signal) def my_callback(sender, **more): print sender print more print "my callback called" custom_signal.send_robust(sender=ak, aa=1, bb=2) custom_signal.send(sender=Demo2, cc=1, dd=2)
时间: 2024-10-07 17:02:15