Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

770: Move shared array allocation to multiprocessing.Array when on Python 3.8 #856

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes/next.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Fixes
- #820 : Help links go to wrong page
- #836 : Median filter returning data from wrong images
- #843 : Error loading stack
- #856 : Move shared array allocation to `multiprocessing.Array` when on Python 3.8
13 changes: 3 additions & 10 deletions mantidimaging/core/parallel/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import os
from functools import partial
from logging import getLogger
# COMPAT python 3.7 : Using heap instead of Array,
# see https://github.com/mantidproject/mantidimaging/pull/762#issuecomment-741663482
from multiprocessing import heap # type: ignore
from multiprocessing import Array
from multiprocessing.pool import Pool
from typing import Any, List, Tuple, Type, Union

Expand Down Expand Up @@ -76,13 +74,8 @@ def _create_shared_array(shape, dtype: Union[str, np.dtype] = np.float32):

LOG.info('Requested shared array with shape={}, length={}, size={}, ' 'dtype={}'.format(shape, length, size, dtype))

arena = heap.Arena(size)
mem = memoryview(arena.buffer)

array_type = ctype * length
array = array_type.from_buffer(mem)

data = np.frombuffer(array, dtype=dtype)
array = Array(ctype, length)
data = np.frombuffer(array.get_obj(), dtype=dtype)

return data.reshape(shape)

Expand Down