def init_data_listener(self):
for listener_name, listener in inspect.getmembers(self, lambda f: hasattr(f, 'events')):
for event in listener.events:
event += listener
@abc.abstractmethod
def destroy(self):
raise NotImplementedError
以下为测试代码
class TestEntiy(ManagerBase):
def __init__(self):
super(TestEntiy, self).__init__()
@msg_listener(game_msg_recv)
def update(self, protocol):
print "this is deal data:", protocol
def destroy(self):
MsgNotifierEvent.clear("game_msg_recv")
test = TestEntiy()
game_msg_recv("i am test1")
test.destroy()
game_msg_recv("i am test2")
#输出
#this is deal data: i am test1
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx