def _event_loop(self):
cls = type(self)
while self._is_active:
try:
evt = cls.events.get(block=False)
except eventlet.queue.Empty:
eventlet.sleep(self._loop_period)
continue
except Exception as e:
logger.exception(e)
continue
if evt == self._evt_stop:
continue
evt_cls = type(evt)
# locate the handler method
handlers = cls.handlers.get(evt_cls)
if not handlers:
raise Exception('%s did not register event: %s' %
(cls.__name__, evt_cls.__name__))
# invoke the handler method
for handler in handlers:
handler(evt)
评论列表
文章目录