mbus.py 文件源码

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

项目:wade 作者: chartbeat-labs 项目源码 文件源码
def req(self, data, timeout):
        """Sends data to the other side and waits for a response.

        If no response within timeout period (or connection failure)
        then raises an error.

        """

        # fixme: handle timeout

        packer = msgpack.Packer()
        unpacker = msgpack.Unpacker()
        with self._sock_lock:
            # fixme: handle some errors here
            #print "sending data", data
            self._sock.sendall(packer.pack(data))
            while True:
                amt = self._sock.recv_into(self._req_buffer, 1000000)
                if not self._req_buffer:
                    raise ValueError("socket closed fixme: raise real error")
                unpacker.feed(self._req_mv[:amt])
                for m in unpacker:
                    # We only expect a single message in response
                    # because of the synchronous pattern from sendall.
                    return m
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号