提交 3adaf7f5 编写于 作者: X Xinghai Sun

Add comments for new classes.

上级 4987f5c5
...@@ -11,7 +11,6 @@ import time ...@@ -11,7 +11,6 @@ import time
import numpy as np import numpy as np
from threading import Thread from threading import Thread
import signal import signal
import multiprocessing
from multiprocessing import Manager, Process from multiprocessing import Manager, Process
import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm
import data_utils.augmentor.trans_add_delta as trans_add_delta import data_utils.augmentor.trans_add_delta as trans_add_delta
......
...@@ -77,6 +77,15 @@ class CriticalException(Exception): ...@@ -77,6 +77,15 @@ class CriticalException(Exception):
class SharedNDArray(object): class SharedNDArray(object):
"""SharedNDArray utilizes shared memory to avoid data serialization when
object of which shared between different processes. We can reconstruct the
ndarray when memory address provided.
Args:
name (str): Address name of shared memory.
is_verify (bool): Whether to do validation for writing operation.
"""
def __init__(self, name, is_verify=False): def __init__(self, name, is_verify=False):
self._name = name self._name = name
self._shm = None self._shm = None
...@@ -130,6 +139,18 @@ class SharedNDArray(object): ...@@ -130,6 +139,18 @@ class SharedNDArray(object):
class SharedMemoryPoolManager(object): class SharedMemoryPoolManager(object):
"""SharedMemoryPoolManager maintains a multiprocessing.Manager.dict object.
All available addresses are allocated once and will be reused. Though this
class is not process-safe, the pool can be shared between processes. All
shared memory should be unlinked before the main process exited.
Args:
pool_size (int): Size of shared memory pool.
manager (dict): A multiprocessing.Manager object, the pool is
maintained by the proxy process.
name_prefix (str): Address prefix of shared memory.
"""
def __init__(self, pool_size, manager, name_prefix='/deep_asr'): def __init__(self, pool_size, manager, name_prefix='/deep_asr'):
self._names = [] self._names = []
self._dict = manager.dict() self._dict = manager.dict()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册