@@ -77,6 +77,15 @@ class CriticalException(Exception):
7777
7878
7979class SharedNDArray (object ):
80+ """SharedNDArray utilizes shared memory to avoid data serialization when
81+ object of which shared between different processes. We can reconstruct the
82+ ndarray when memory address provided.
83+
84+ Args:
85+ name (str): Address name of shared memory.
86+ is_verify (bool): Whether to do validation for writing operation.
87+ """
88+
8089 def __init__ (self , name , is_verify = False ):
8190 self ._name = name
8291 self ._shm = None
@@ -130,6 +139,18 @@ def __setstate__(self, state):
130139
131140
132141class SharedMemoryPoolManager (object ):
142+ """SharedMemoryPoolManager maintains a multiprocessing.Manager.dict object.
143+ All available addresses are allocated once and will be reused. Though this
144+ class is not process-safe, the pool can be shared between processes. All
145+ shared memory should be unlinked before the main process exited.
146+
147+ Args:
148+ pool_size (int): Size of shared memory pool.
149+ manager (dict): A multiprocessing.Manager object, the pool is
150+ maintained by the proxy process.
151+ name_prefix (str): Address prefix of shared memory.
152+ """
153+
133154 def __init__ (self , pool_size , manager , name_prefix = '/deep_asr' ):
134155 self ._names = []
135156 self ._dict = manager .dict ()
0 commit comments