I'm trying to use ProcessPoolExecutor with the following function:
def get_ellipse_properties(a,b,mask=mask):
''' a - int time frame value of a feature
b - int feature id number
mask- iris cube with segmentation mask'''
feat_mask = mask_features(mask,b) #create mask for specific features
frame_mask = feat_mask[a].data
labels, num_labels = label(frame_mask, background=0, return_num=True) #skimage.measure function
ellipse_features = {}
try:
label_props = get_label_props_in_dict(labels) #get label properties into dictionary format
if len(label_props.keys()) > 1:
print('More than one key found in the dictionary')
list_of_props = [label_props[1].eccentricity, label_props[1].centroid,
label_props[1].axis_major_length, label_props[1].axis_minor_length, label_props[1].orientation]
#eccentricity, centroid, axis_major, axis_minor, orientation
ellipse_features[b] = list_of_props
except:
ellipse_features[b] = np.nan
return ellipse_features
This is the part of the code with the executor:
def main():
start = time()
pool = concurrent.futures.ProcessPoolExecutor(mp_context=mp.get_context('fork'),max_workers=30)
results = list(pool.map(get_ellipse_properties,frame1,feature1))
end = time()
print('Took %.3f seconds' % (end - start))
return results
if __name__ == '__main__':
main()
The issue is when I try to use the executor with this function, it hangs. It doesn't throw any errors, it just freezes. I know it has something to do with my function because it worked fine with other simple functions, but I cannot figure out what exactly causes this issue. It worked well with ThreadPoolExecutor, but ThreadPool didn't speed up compared to for loop. I will be grateful for any suggestions.