From f9a84f073266ab5e0137e76d06515cd4a8dacefd Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 19 Oct 2022 14:20:50 -0400 Subject: [PATCH] Allocate size-specced "empty" sequence from default values by type --- tractor/_shm.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tractor/_shm.py b/tractor/_shm.py index 79ac896..2ce148d 100644 --- a/tractor/_shm.py +++ b/tractor/_shm.py @@ -719,7 +719,7 @@ class ShmList(ShareableList): Carbon copy of ``.shared_memory.ShareableList`` with a few enhancements: - - readonly mode via instance var flag + - readonly mode via instance var flag `._readonly: bool` - ``.__getitem__()`` accepts ``slice`` inputs - exposes the underlying buffer "name" as a ``.key: str`` @@ -743,6 +743,10 @@ class ShmList(ShareableList): def key(self) -> str: return self._key + @property + def readonly(self) -> bool: + return self._readonly + def __setitem__( self, position, @@ -781,13 +785,21 @@ def open_shm_list( key: str, sequence: list | None = None, size: int = int(2 ** 10), - dtype: np.dtype | None = None, + dtype: float | int | bool | str | bytes | None = float, readonly: bool = True, ) -> ShmList: if sequence is None: - sequence = list(map(float, range(size))) + default = { + float: 0., + int: 0, + bool: True, + str: 'doggy', + None: None, + }[dtype] + sequence = [default] * size + # sequence = [0.] * size shml = ShmList( sequence=sequence,