api.py 文件源码

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

项目:openag_brain 作者: OpenAgInitiative 项目源码 文件源码
def stream_topic(topic_name):
    """
    GET /api/<version>/topic_stream/<topic_name>

    Stream a topic over HTTP by keeping the http connection alive.
    """
    topic_name = "/" + topic_name
    try:
        msg_class, real_topic, _ = rostopic.get_topic_class(topic_name)
    except rostopic.ROSTopicIOException as e:
        raise e
    if not real_topic:
        return error("Topic does not exist", 404)
    queue = Queue(5)
    def callback(dataIn, queue=queue):
        data = getattr(dataIn, "data", None)
        if data is None:
            data = {"header": getattr(dataIn, "header"), "status": getattr(dataIn, "status")}
        queue.put(data)
    sub = rospy.Subscriber(real_topic, msg_class, callback)
    def gen(queue=queue):
        while True:
            x = queue.get()
            yield str(x) + "\n"
    return Response(gen(),  mimetype='text/plain')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号