本文整理汇总了Python中multiprocessing.reduction方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocessing.reduction方法的具体用法?Python multiprocessing.reduction怎么用?Python multiprocessing.reduction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing
的用法示例。
在下文中一共展示了multiprocessing.reduction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _winapi_childhandle_after_createprocess_child
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import reduction [as 别名]
def _winapi_childhandle_after_createprocess_child(self):
"""Called on Windows in the child process after the CreateProcess()
system call. This is required for making the handle usable in the child.
"""
if WINAPI_HANDLE_TRANSFER_STEAL:
# In this case the handle has not been inherited by the child
# process during CreateProcess(). Steal it from the parent.
new_winapihandle = multiprocessing.reduction.steal_handle(
self._parent_pid, self._parent_winapihandle)
del self._parent_winapihandle
del self._parent_pid
# Restore C file descriptor with (read/write)only flag.
self._fd = msvcrt.open_osfhandle(new_winapihandle, self._fd_flag)
return
# In this case the handle has been inherited by the child process during
# the CreateProcess() system call. Get C file descriptor from Windows
# file handle.
self._fd = msvcrt.open_osfhandle(
self._inheritable_winapihandle, self._fd_flag)
del self._inheritable_winapihandle
示例2: rebuild_ndarray
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import reduction [as 别名]
def rebuild_ndarray(pid, fd, shape, dtype):
"""Rebuild ndarray from pickled shared memory"""
# pylint: disable=no-value-for-parameter
if sys.version_info[0] == 2:
fd = multiprocessing.reduction.rebuild_handle(fd)
else:
fd = fd.detach()
return nd.NDArray(nd.ndarray._new_from_shared_mem(pid, fd, shape, dtype))
示例3: reduce_ndarray
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import reduction [as 别名]
def reduce_ndarray(data):
"""Reduce ndarray to shared memory handle"""
# keep a local ref before duplicating fd
data = data.as_in_context(context.Context('cpu_shared', 0))
pid, fd, shape, dtype = data._to_shared_mem()
if sys.version_info[0] == 2:
fd = multiprocessing.reduction.reduce_handle(fd)
else:
fd = multiprocessing.reduction.DupFd(fd)
return rebuild_ndarray, (pid, fd, shape, dtype)
示例4: reduce_ndarray
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import reduction [as 别名]
def reduce_ndarray(data):
"""Reduce ndarray to shared memory handle"""
# keep a local ref before duplicating fd
data = data.as_in_context(context.Context("cpu_shared", 0))
pid, fd, shape, dtype = data._to_shared_mem()
fd = multiprocessing.reduction.DupFd(fd)
return rebuild_ndarray, (pid, fd, shape, dtype)