本文整理匯總了Python中joblib.pool.MemmapingPool.apply_async方法的典型用法代碼示例。如果您正苦於以下問題:Python MemmapingPool.apply_async方法的具體用法?Python MemmapingPool.apply_async怎麽用?Python MemmapingPool.apply_async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類joblib.pool.MemmapingPool
的用法示例。
在下文中一共展示了MemmapingPool.apply_async方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_memmaping_pool_for_large_arrays_in_return
# 需要導入模塊: from joblib.pool import MemmapingPool [as 別名]
# 或者: from joblib.pool.MemmapingPool import apply_async [as 別名]
def test_memmaping_pool_for_large_arrays_in_return(tmpdir):
"""Check that large arrays are not copied in memory in return"""
assert_array_equal = np.testing.assert_array_equal
# Build an array reducers that automaticaly dump large array content
# but check that the returned datastructure are regular arrays to avoid
# passing a memmap array pointing to a pool controlled temp folder that
# might be confusing to the user
# The MemmapingPool user can always return numpy.memmap object explicitly
# to avoid memory copy
p = MemmapingPool(3, max_nbytes=10, temp_folder=tmpdir.strpath)
try:
res = p.apply_async(np.ones, args=(1000,))
large = res.get()
assert not has_shareable_memory(large)
assert_array_equal(large, np.ones(1000))
finally:
p.terminate()
del p
示例2: test_workaround_against_bad_memmap_with_copied_buffers
# 需要導入模塊: from joblib.pool import MemmapingPool [as 別名]
# 或者: from joblib.pool.MemmapingPool import apply_async [as 別名]
def test_workaround_against_bad_memmap_with_copied_buffers(tmpdir):
"""Check that memmaps with a bad buffer are returned as regular arrays
Unary operations and ufuncs on memmap instances return a new memmap
instance with an in-memory buffer (probably a numpy bug).
"""
assert_array_equal = np.testing.assert_array_equal
p = MemmapingPool(3, max_nbytes=10, temp_folder=tmpdir.strpath)
try:
# Send a complex, large-ish view on a array that will be converted to
# a memmap in the worker process
a = np.asarray(np.arange(6000).reshape((1000, 2, 3)),
order='F')[:, :1, :]
# Call a non-inplace multiply operation on the worker and memmap and
# send it back to the parent.
b = p.apply_async(_worker_multiply, args=(a, 3)).get()
assert not has_shareable_memory(b)
assert_array_equal(b, 3 * a)
finally:
p.terminate()
del p