Skip to content

Commit

Permalink
Instantiate the multiprocessing pool using with (#1436)
Browse files Browse the repository at this point in the history
This ensures we shut down the pool when complete.

Test plan: `pytest -v -n4  starfish/core/spots/`
Fixes: #1435
  • Loading branch information
Tony Tung authored Jul 9, 2019
1 parent 8a7992b commit 5842aca
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions starfish/core/spots/_detect_pixels/combine_adjacent_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,29 @@ def _create_spot_attributes(
An array with length equal to the number of features. If zero, indicates that a feature
has failed area filters.
"""
pool = Pool(processes=n_processes)
mapfunc = pool.map
applyfunc = partial(
self._single_spot_attributes,
decoded_image=decoded_image,
target_map=target_map,
min_area=self._min_area,
max_area=self._max_area
)
with Pool(processes=n_processes) as pool:
mapfunc = pool.map
applyfunc = partial(
self._single_spot_attributes,
decoded_image=decoded_image,
target_map=target_map,
min_area=self._min_area,
max_area=self._max_area
)

iterable = tqdm(region_properties, disable=(not StarfishConfig().verbose))
results = mapfunc(applyfunc, iterable)
if not results:
# no spots found
warnings.warn("No spots found, please adjust threshold parameters")
return SpotAttributes.empty(extra_fields=['target']), np.array(0, dtype=np.bool)
spot_attrs, passes_area_filter = zip(*results)
iterable = tqdm(region_properties, disable=(not StarfishConfig().verbose))
results = mapfunc(applyfunc, iterable)
if not results:
# no spots found
warnings.warn("No spots found, please adjust threshold parameters")
return SpotAttributes.empty(extra_fields=['target']), np.array(0, dtype=np.bool)
spot_attrs, passes_area_filter = zip(*results)

# update passes filter
passes_filter = np.array(passes_area_filter, dtype=np.bool)
# update passes filter
passes_filter = np.array(passes_area_filter, dtype=np.bool)

spot_attributes = SpotAttributes(pd.DataFrame.from_records(spot_attrs))
return spot_attributes, passes_filter
spot_attributes = SpotAttributes(pd.DataFrame.from_records(spot_attrs))
return spot_attributes, passes_filter

def run(
self, intensities: IntensityTable,
Expand Down

0 comments on commit 5842aca

Please sign in to comment.