reactor.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:eventdriventalk 作者: cachedout 项目源码 文件源码
def process_event(self, event):
        '''
        Take an event and attempt to match it
        in the list of keys.

        If found, schedule the requested action.
        '''
        if not self.opts:
            return
        for tag in self.opts:
            if fnmatch.fnmatch(event['tag'], tag):
                for action in self.opts[tag]['reactions']:
                    # Super-simple non-blocking appraoch
                    # Threading won't scale as much as a true event loop
                    # would. It will, however, handle cases where single-threaded
                    # loop would be blocked. Do you trust your reactions to be co-op?!
                    # Of course, the other side of this is thread-safety. Either way, be smart!
                    t = threading.Thread(target=self.react, args=(action, event))
                    t.start()
                if 'rules' in self.opts[tag]:
                    rule_actions = []
                for rule in self.opts[tag]['rules']:
                    rule_actions = process_rule(rule, event, tracking_id)
                    if rule_actions:
                        for action in rule_actions:
                            self.react(action.keys()[0], action.values())
                    else:
                        # Rule chaining ends when a rule does not match
                        break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号