Add `ShmList` slice support in `.__getitem__()`

macos_in_ci
Tyler Goodlet 2022-10-18 11:01:02 -04:00
parent 60f8f110e8
commit 2ac19b2e96
1 changed files with 24 additions and 5 deletions

View File

@ -26,20 +26,26 @@ from __future__ import annotations
from sys import byteorder from sys import byteorder
import time import time
from typing import Optional from typing import Optional
from multiprocessing import shared_memory as shm
from multiprocessing.shared_memory import ( from multiprocessing.shared_memory import (
SharedMemory, SharedMemory,
ShareableList, ShareableList,
_USE_POSIX, # type: ignore # _USE_POSIX, # type: ignore
) )
if _USE_POSIX: if getattr(shm, '_USE_POSIX', False):
from _posixshmem import shm_unlink from _posixshmem import shm_unlink
from msgspec import Struct from msgspec import Struct
import numpy as np
from numpy.lib import recfunctions as rfn
import tractor import tractor
try:
import numpy as np
from numpy.lib import recfunctions as rfn
import nptyping
except ImportError:
pass
from .log import get_logger from .log import get_logger
@ -742,6 +748,15 @@ class ShmList(ShareableList):
return super().__setitem__(position, value) return super().__setitem__(position, value)
def __getitem__(
self,
indexish,
) -> list:
if isinstance(indexish, slice):
return list(self)[indexish]
return super().__getitem__(indexish)
def open_shm_list( def open_shm_list(
key: str, key: str,
@ -774,7 +789,11 @@ def open_shm_list(
def attach_shm_list( def attach_shm_list(
key: str, key: str,
readonly: bool = False,
) -> ShmList: ) -> ShmList:
return ShmList(name=key) return ShmList(
name=key,
readonly=readonly,
)