当前位置: 首页>>代码示例>>Python>>正文


Python msgpack_numpy.decode方法代码示例

本文整理汇总了Python中msgpack_numpy.decode方法的典型用法代码示例。如果您正苦于以下问题:Python msgpack_numpy.decode方法的具体用法?Python msgpack_numpy.decode怎么用?Python msgpack_numpy.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msgpack_numpy的用法示例。


在下文中一共展示了msgpack_numpy.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _blocking_request

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def _blocking_request(self, _request):
        """
            request:
                -command_type
                -payload
                -response_channel
            response: (on response_channel)
                - RESULT
            * Send the payload on command_channel (self.namespace+"::command")
                ** redis-left-push (LPUSH)
            * Keep listening on response_channel (BLPOP)
        """
        assert type(_request) ==type({})
        _request['response_channel'] = self._generate_response_channel()

        _redis = self.get_redis_connection()
        """
            The client always pushes in the left
            and the service always pushes in the right
        """
        if self.verbose: print("Request : ", _response)
        # Push request in command_channels
        payload = msgpack.packb(_request, default=m.encode, use_bin_type=True)
        _redis.lpush(self.command_channel, payload)
        ## TODO: Check if we can use `repr` for json.dumps string serialization
        # Wait with a blocking pop for the response
        _response = _redis.blpop(_request['response_channel'])[1]
        if self.verbose: print("Response : ", _response)
        _response = msgpack.unpackb(_response, object_hook=m.decode, encoding="utf8")
        if _response['type'] == messages.OSIM_RL.ERROR:
            raise Exception(str(_response))
        else:
            return _response 
开发者ID:stanfordnmbl,项目名称:osim-rl,代码行数:35,代码来源:client.py

示例2: receive_loop

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def receive_loop(self):
        """
        This is the receive loop for zmq messages.

        This method may be overwritten to meet the needs
        of the application before handling received messages.

        :return:
        """
        for element in itertools.cycle(self.backplane_table):
            if element['subscriber']:
                try:
                    data = element['subscriber'].recv_multipart(zmq.NOBLOCK)
                    if self.numpy:
                        payload = msgpack.unpackb(data[1], object_hook=m.decode)
                        self.incoming_message_processing(data[0].decode(), payload)
                    else:
                        self.incoming_message_processing(data[0].decode(), umsgpack.unpackb(data[1]))
                except zmq.error.Again:
                    try:
                        time.sleep(self.loop_time)
                    except KeyboardInterrupt:
                        self.clean_up()
                        sys.exit(0)
                except AttributeError:
                    raise 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:28,代码来源:banyan_base_multi.py

示例3: numpy_unpack

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def numpy_unpack(self, data):
        return msgpack.unpackb(data[1], object_hook=m.decode) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:4,代码来源:banyan_base_aio.py

示例4: receive_loop

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def receive_loop(self):
        """
        This is the receive loop for Banyan messages.

        This method may be overwritten to meet the needs
        of the application before handling received messages.

        """
        while True:
            data = await self.subscriber.recv_multipart()
            if self.numpy:
                payload2 = {}
                payload = await self.numpy_unpack(data[1])
                # convert keys to strings
                # this compensates for the breaking change in msgpack-numpy 0.4.1 to 0.4.2
                for key, value in payload.items():
                    if not type(key) == str:
                        key = key.decode('utf-8')
                        payload2[key] = value

                if payload2:
                    payload = payload2
                await self.incoming_message_processing(data[0].decode(), payload)
            else:
                payload = await self.unpack(data[1])
                await self.incoming_message_processing(data[0].decode(), payload) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:28,代码来源:banyan_base_aio.py

示例5: receive_loop

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def receive_loop(self):
        """
        This is the receive loop for Banyan messages.

        This method may be overwritten to meet the needs
        of the application before handling received messages.

        """
        while True:
            try:
                data = self.subscriber.recv_multipart(zmq.NOBLOCK)
                if self.numpy:
                    payload2 = {}
                    payload = msgpack.unpackb(data[1], object_hook=m.decode)
                    # convert keys to strings
                    # this compensates for the breaking change in msgpack-numpy 0.4.1 to 0.4.2
                    for key, value in payload.items():
                        if not type(key) == str:
                            key = key.decode('utf-8')
                            payload2[key] = value

                    if payload2:
                        payload = payload2
                    self.incoming_message_processing(data[0].decode(), payload)
                else:
                    self.incoming_message_processing(data[0].decode(),
                                                     msgpack.unpackb(data[1], raw=False))
            # if no messages are available, zmq throws this exception
            except zmq.error.Again:
                try:
                    if self.receive_loop_idle_addition:
                        self.receive_loop_idle_addition()
                    time.sleep(self.loop_time)
                except KeyboardInterrupt:
                    self.clean_up()
                    raise KeyboardInterrupt 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:38,代码来源:banyan_base.py

示例6: np_deserialize

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def np_deserialize(s):
  import msgpack
  import msgpack_numpy as m
  return msgpack.unpackb(s, object_hook=m.decode)
#  return np.load(StringIO.StringIO(s)) 
开发者ID:andrewowens,项目名称:multisensory,代码行数:7,代码来源:util.py

示例7: unserialize

# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def unserialize(self, serialized_vector):
        """ Unserialize a vector using msgpack.

        :param bytes serialized_vector:
        :return np.array:
        """
        return msgpack.unpackb(
            serialized_vector,
            object_hook = msgpack_numpy.decode,
            raw = self._raw
        ) 
开发者ID:ThoughtRiver,项目名称:lmdb-embeddings,代码行数:13,代码来源:serializers.py


注:本文中的msgpack_numpy.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。