当前位置: 首页>>代码示例>>Python>>正文


Python multiprocessing.RawValue方法代码示例

本文整理汇总了Python中multiprocessing.RawValue方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocessing.RawValue方法的具体用法?Python multiprocessing.RawValue怎么用?Python multiprocessing.RawValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing的用法示例。


在下文中一共展示了multiprocessing.RawValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, *, slot_bytes, slot_count):
        """Initializer.

        Args:
            slot_bytes: The maximum size of slots in the buffer.
            slot_count: How many slots should be in the buffer.
        """
        self.slot_count = slot_count
        self.array = SlotArray(slot_bytes=slot_bytes, slot_count=slot_count)
        self.lock = ReadersWriterLock()
        # Each reading process may modify its own Pointer while the read
        # lock is being held. Each reading process can also load the position
        # of the writer, but not load any other readers. Each reading process
        # can also load the value of the 'active' count.
        self.readers = []
        # The writer can load and store the Pointer of all the reader Pointers
        # or the writer Pointer while the write lock is held. It can also load
        # and store the value of the 'active' acount.
        self.writer = Pointer(self.slot_count)
        self.active = multiprocessing.RawValue(ctypes.c_uint, 0) 
开发者ID:bslatkin,项目名称:ringbuffer,代码行数:22,代码来源:ringbuffer.py

示例2: test_value

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def test_value(self, raw=False):
        if raw:
            values = [self.RawValue(code, value)
                      for code, value, _ in self.codes_values]
        else:
            values = [self.Value(code, value)
                      for code, value, _ in self.codes_values]

        for sv, cv in zip(values, self.codes_values):
            self.assertEqual(sv.value, cv[1])

        proc = self.Process(target=self._test, args=(values,))
        proc.daemon = True
        proc.start()
        proc.join()

        for sv, cv in zip(values, self.codes_values):
            self.assertEqual(sv.value, cv[2]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:_test_multiprocessing.py

示例3: test_getobj_getlock

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def test_getobj_getlock(self):
        val1 = self.Value('i', 5)
        lock1 = val1.get_lock()
        obj1 = val1.get_obj()

        val2 = self.Value('i', 5, lock=None)
        lock2 = val2.get_lock()
        obj2 = val2.get_obj()

        lock = self.Lock()
        val3 = self.Value('i', 5, lock=lock)
        lock3 = val3.get_lock()
        obj3 = val3.get_obj()
        self.assertEqual(lock, lock3)

        arr4 = self.Value('i', 5, lock=False)
        self.assertFalse(hasattr(arr4, 'get_lock'))
        self.assertFalse(hasattr(arr4, 'get_obj'))

        self.assertRaises(AttributeError, self.Value, 'i', 5, lock='navalue')

        arr5 = self.RawValue('i', 5)
        self.assertFalse(hasattr(arr5, 'get_lock'))
        self.assertFalse(hasattr(arr5, 'get_obj')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:_test_multiprocessing.py

示例4: build_ctrl

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def build_ctrl(self, world_size):
        """
        Builds several parallel communication mechanisms for controlling the
        workflow across processes.
        """
        opt_throttle = (mp.Barrier(world_size) if world_size > 1 else
            None)
        return AttrDict(
            quit=mp.Value('b', lock=True),
            quit_opt=mp.RawValue('b'),
            sample_ready=[mp.Semaphore(0) for _ in range(2)],  # Double buffer.
            sample_copied=[mp.Semaphore(1) for _ in range(2)],
            sampler_itr=mp.Value('l', lock=True),
            opt_throttle=opt_throttle,
            eval_time=mp.Value('d', lock=True),
        ) 
开发者ID:astooke,项目名称:rlpyt,代码行数:18,代码来源:async_rl.py

示例5: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, ModelCls=None, model_kwargs=None, initial_model_state_dict=None):
        """
        Arguments are saved but no model initialization occurs.

        Args:
            ModelCls: The model class to be used.
            model_kwargs (optional): Any keyword arguments to pass when instantiating the model.
            initial_model_state_dict (optional): Initial model parameter values.
        """

        save__init__args(locals())
        self.model = None  # type: torch.nn.Module
        self.shared_model = None
        self.distribution = None
        self.device = torch.device("cpu")
        self._mode = None
        if self.model_kwargs is None:
            self.model_kwargs = dict()
        # The rest only for async operations:
        self._rw_lock = RWLock()
        self._send_count = mp.RawValue("l", 0)
        self._recv_count = 0 
开发者ID:astooke,项目名称:rlpyt,代码行数:24,代码来源:base.py

示例6: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, ndata, nprocs, chunk=None, schedule='guided'):
        if not schedule in ['guided', 'dynamic', 'static']:
            raise ValueError('unknown scheduling strategy')
        self._ndata = mp.RawValue(ctypes.c_int, ndata)
        self._start = mp.RawValue(ctypes.c_int, 0)
        self._lock = mp.Lock()
        self._schedule = schedule
        self._nprocs = nprocs
        if schedule == 'guided' or schedule == 'dynamic':
            min_chunk = ndata // (10 * nprocs)
            if chunk:
                min_chunk = chunk
            min_chunk = max(min_chunk, 1)
            self._chunk = min_chunk
        elif schedule == 'static':
            min_chunk = ndata // nprocs
            if chunk:
                min_chunk = max(chunk, min_chunk)
            min_chunk = max(min_chunk, 1)
            self._chunk = min_chunk 
开发者ID:pytroll,项目名称:pyresample,代码行数:22,代码来源:_multi_proc.py

示例7: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, params, opt_type=None, lr=0, step=0):
        self.var_shapes = [
            var.get_shape().as_list()
            for var in params]
        self.size = sum([np.prod(shape) for shape in self.var_shapes])
        self.step = RawValue(ctypes.c_int, step)

        if opt_type == 'adam':
            self.ms = self.malloc_contiguous(self.size)
            self.vs = self.malloc_contiguous(self.size)
            self.lr = RawValue(ctypes.c_float, lr)
        elif opt_type == 'adamax':
            self.ms = self.malloc_contiguous(self.size)
            self.vs = self.malloc_contiguous(self.size)
            self.lr = RawValue(ctypes.c_float, lr)
        elif opt_type == 'rmsprop':
            self.vars = self.malloc_contiguous(self.size, np.ones(self.size, dtype=np.float))
        elif opt_type == 'momentum':
            self.vars = self.malloc_contiguous(self.size)
        else:
            self.vars = self.malloc_contiguous(self.size) 
开发者ID:steveKapturowski,项目名称:tensorflow-rl,代码行数:23,代码来源:shared_memory.py

示例8: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, delta_list_queue, comp_delta_queue,
                 overlay_mode,
                 block_size=1024*1024*2):
        """
        comparisons of compression algorithm
        http://pokecraft.first-world.info/wiki/Quick_Benchmark:_Gzip_vs_Bzip2_vs_LZMA_vs_XZ_vs_LZ4_vs_LZO
        """
        self.delta_list_queue = delta_list_queue
        self.comp_delta_queue = comp_delta_queue
        self.overlay_mode = overlay_mode
        self.num_proc = VMOverlayCreationMode.MAX_THREAD_NUM
        self.comp_type = overlay_mode.COMPRESSION_ALGORITHM_TYPE
        self.comp_level = overlay_mode.COMPRESSION_ALGORITHM_SPEED
        self.block_size = block_size
        self.proc_list = list()

        # monitor value specific to compression
        self.monitor_time_first_input_recved = multiprocessing.RawValue(
            ctypes.c_double, 0)

        super(CompressProc, self).__init__(target=self.compress_stream) 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:23,代码来源:compression.py

示例9: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, remote_addr, remote_port, metadata, compdata_queue, process_controller):
        self.remote_addr = remote_addr
        self.remote_port = remote_port
        self.metadata = metadata
        self.compdata_queue = compdata_queue
        self.process_controller = process_controller

        # measurement
        self.monitor_network_bw = multiprocessing.RawValue(ctypes.c_double, 0)
        self.monitor_network_bw.value = 0.0
        self.vm_resume_time_at_dest = multiprocessing.RawValue(ctypes.c_double, 0)
        self.time_finish_transmission = multiprocessing.RawValue(ctypes.c_double, 0)

        self.is_first_recv = False
        self.time_first_recv = 0

        super(StreamSynthesisClient, self).__init__(target=self.transfer) 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:19,代码来源:stream_client.py

示例10: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, modified_mem_queue, deltalist_queue,
                 basemem_meta, basemem_path, overlay_mode,
                 apply_free_memory=True,
                 free_memory_info=None):
        self.modified_mem_queue = modified_mem_queue
        self.deltalist_queue = deltalist_queue
        self.basemem_meta = basemem_meta
        self.memory_hashlist = Memory.import_hashlist(basemem_meta)
        self.apply_free_memory = apply_free_memory
        self.free_memory_info = free_memory_info
        self.basemem_path = basemem_path
        self.proc_list = list()
        self.overlay_mode = overlay_mode
        self.num_proc = VMOverlayCreationMode.MAX_THREAD_NUM
        self.diff_algorithm = overlay_mode.MEMORY_DIFF_ALGORITHM

        self.monitor_current_iteration = multiprocessing.RawValue(
            ctypes.c_ulong, 0)

        super(CreateMemoryDeltalist, self).__init__(
            target=self.create_memory_deltalist) 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:23,代码来源:memory.py

示例11: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, command_queue, task_queue, mode_queue, deltalist_queue,
                 diff_algorithm, basedisk_path, modified_disk, chunk_size):
        self.command_queue = command_queue
        self.task_queue = task_queue
        self.mode_queue = mode_queue
        self.deltalist_queue = deltalist_queue
        self.diff_algorithm = diff_algorithm
        self.basedisk_path = basedisk_path
        self.modified_disk = modified_disk
        self.chunk_size = chunk_size

        # shared variables between processes
        self.child_process_time_total = multiprocessing.RawValue(
            ctypes.c_double, 0)
        self.child_process_block_total = multiprocessing.RawValue(
            ctypes.c_double, 0)
        self.child_input_size_total = multiprocessing.RawValue(
            ctypes.c_ulong, 0)
        self.child_output_size_total = multiprocessing.RawValue(
            ctypes.c_ulong, 0)

        super(DiskDiffProc, self).__init__(target=self.process_diff) 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:24,代码来源:disk.py

示例12: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, initval=0):
        self.val = RawValue('i', initval)
        self.last_step_update_target = RawValue('i', initval)
        self.lock = Lock() 
开发者ID:traai,项目名称:async-deep-rl,代码行数:6,代码来源:shared_utils.py

示例13: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, value=0):
        self.initial_value = value
        self.val = RawValue('i', value)
        self.lock = Lock() 
开发者ID:ndbroadbent,项目名称:icloud_photos_downloader,代码行数:6,代码来源:counter.py

示例14: reset

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def reset(self):
        with self.lock:
            self.val = RawValue('i', self.initial_value) 
开发者ID:ndbroadbent,项目名称:icloud_photos_downloader,代码行数:5,代码来源:counter.py

示例15: __init__

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, context_size):
        # use raw values because both indices have
        # to manually be locked together
        self._doc_id = multiprocessing.RawValue('i', 0)
        self._in_doc_pos = multiprocessing.RawValue('i', context_size)
        self._lock = multiprocessing.Lock() 
开发者ID:inejc,项目名称:paragraph-vectors,代码行数:8,代码来源:data.py


注:本文中的multiprocessing.RawValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。