Python样例
from blinker import Namespace # 创建一个Signal,其名为test my_singal = Namespace() test = my_singal.signal('test') # 创建一个方法singal_sender,内部包含两个发送者 def singal_sender(): # 发送者test1 test.send('test1', data1=1) # 发送者test2 test.send('test2', data2=2) print('singal_sender() 执行完毕') # 订阅者,指定接收test1 @test.connect_via('test1') def subscriber(sender, **kwargs): print("指定接收test1", sender, kwargs) # 订阅者,指定接收test2 @test.connect_via('test2') def subscriber(sender, **kwargs): print("指定接收test2", sender, kwargs) # 订阅者,不指定接收,全部发布都要接收 @test.connect def subscriber(sender, **kwargs): print("不指定接收", sender, kwargs) singal_sender()