__init__.py 文件源码

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

项目:Locus 作者: senditya 项目源码 文件源码
def messenger():
    while True:
        sleep(5)
        app.logger.debug("Inside Messenger Iteration")
        msgs = poll_topics()
        ads = dict()
        for topic in msgs.keys():
            all_msgs = msgs[topic]
            ads[topic] = dict()
            for msg in all_msgs:
                offset = msg[2]
                ad = msg[-1]
                ads[topic][offset] = ad
            # offset = msg.offset
            # ad = msg.value
            # try:
            #     ads[topic][offset] = ad
            # except KeyError:
            #     ads[topic] = dict
            #     ads[topic][offset] = ad

        for sid in client_dict.keys():
            interest_list = client_dict[sid].keys()
            for interest in interest_list:
                regions = client_dict[sid][interest].keys()
                for region in regions:
                    if client_dict[sid][interest][region][0]:
                        offset = client_dict[sid][interest][region][1]
                        while True:
                            try:
                                topic = interest+'_'+region
                                app.logger.debug('Emitting to server with topic ' + topic)
                                ad = ads[topic][offset]
                                # if len(ad) == 0:
                                #     app.logger.debug('ad length was 0')
                                #     continue
                                socketio.emit('server-message', {'topic': topic, 'ad': ad}, room=sid, callback=ack)
                                offset += 1
                            except KeyError:
                                app.logger.debug("Key Error Exception happened")
                                break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号