我正在尝试使用具有以下功能的 ProcessPoolExecutor:
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
这是执行者的代码部分:
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()
问题是当我尝试使用具有此功能的执行程序时,它挂起。它不会抛出任何错误,它只是冻结。我知道它与我的功能有关,因为它可以与其他简单功能一起正常工作,但我无法弄清楚到底是什么导致了这个问题。它与 ThreadPoolExecutor 配合使用效果很好,但与 for 循环相比,ThreadPool 并没有提速。如有任何建议,我将不胜感激。