webapp.py 文件源码

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

项目:pypilot 作者: pypilot 项目源码 文件源码
def background_thread(self):
        print 'processing clients'
        x = 0
        polls_sent = {}
        while True:
            if self.client:
                line = self.client.readline()
                if line:
                    #print 'line', line
                    try:
                        #data = {'data': json.loads(line.rstrip())}
                        #print 'data', data
                        socketio.emit('signalk', line.rstrip())
                    except:
                        socketio.emit('log', line)
                        print 'error: ', line.rstrip()
                    continue

                polls = {}
                for sid in self.polls:
                    for poll in self.polls[sid]:
                        polls[poll] = True
                t = time.time()
                for message in polls:
                    if not message in polls_sent or \
                       t - polls_sent[message] > 1:
                        #print 'msg', message
                        self.client.send(message + '\n')
                        polls_sent[message] = t

                self.client.flush()
                self.client.recv()

            socketio.sleep(.25)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号