initialized = signal('initialized') initialized is signal('initialized') sig = Signal()
可以使用匿名信号槽,也可以使用带名称的信号槽。
1 2 3 4 5 6 7 8 9
from blinker import signal send_data = signal('send-data') @send_data.connect defreceive_data(sender, **kw): print("Caught signal from %r, data %r" % (sender, kw)) return'received!' result = send_data.send('anonymous', abc=123) print(result) # 打印 [(<function receive_data at 0x000002A3328D4DC8>, 'received!')] # 打印 Caught signal from 'anonymous', data {'abc': 123}