File: sharedArray.py

package info (click to toggle)
kineticstools 0.6.1%2Bgit20220223.1326a4d%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,188 kB
  • sloc: python: 3,508; makefile: 200; ansic: 104; sh: 55; xml: 19
file content (21 lines) | stat: -rw-r--r-- 569 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from multiprocessing.sharedctypes import RawArray
import warnings
import numpy as np


class SharedArray:

    """
    Very simple wrapper for a chunk of shared memory that can be accessed across processes
    """

    def __init__(self, dtype, shape):
        self._rawArray = RawArray(dtype, shape)

    def getNumpyWrapper(self):
        """
        Construct a numpy array that wraps the raw shared memory array
        """
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            return np.ctypeslib.as_array(self._rawArray)