From fbd68d2d913f16bf935469f734fa210dd669b35e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 3 Aug 2020 18:41:21 -0400 Subject: [PATCH] Allow for tuple keys with std `msgpack` --- tractor/_ipc.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tractor/_ipc.py b/tractor/_ipc.py index 0d24307..a3a271d 100644 --- a/tractor/_ipc.py +++ b/tractor/_ipc.py @@ -3,6 +3,8 @@ Inter-process comms abstractions """ import typing from typing import Any, Tuple, Optional +from functools import partial +import inspect import msgpack import trio @@ -11,6 +13,14 @@ from async_generator import asynccontextmanager from .log import get_logger log = get_logger('ipc') +# :eyeroll: +try: + import msgpack_numpy + Unpacker = msgpack_numpy.Unpacker +except ImportError: + # just plain ``msgpack`` requires tweaking key settings + Unpacker = partial(msgpack.Unpacker, strict_map_key=False) + class MsgpackStream: """A ``trio.SocketStream`` delivering ``msgpack`` formatted data. @@ -32,7 +42,10 @@ class MsgpackStream: async def _iter_packets(self) -> typing.AsyncGenerator[dict, None]: """Yield packets from the underlying stream. """ - unpacker = msgpack.Unpacker(raw=False, use_list=False) + unpacker = Unpacker( + raw=False, + use_list=False, + ) while True: try: data = await self.stream.receive_some(2**10)