本文整理匯總了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)