我正在尝试通过多重处理来加速脚本的运行时间。当我用更简单的定义(如调整不同目录上的图像大小)尝试相同的多处理代码时,多处理效果很好,但当我用下面看到的代码尝试时,它运行了,但没有给出任何输出或引发任何错误,我想知道这可能是什么原因
我还想知道如何在代码中使用多处理,也许继承是个问题
class Skeleton:
def __init__(self, path, **kwargs):
if type(path) is str:
self.path = path
self.inputStack = loadStack(self.path).astype(bool)
if kwargs != {}:
aspectRatio = kwargs["aspectRatio"]
self.inputStack = ndimage.interpolation.zoom(self.inputStack, zoom=aspectRatio, order=2,
prefilter=False)
def setThinningOutput(self, mode="reflect"):
# Thinning output
self.skeletonStack = get_thinned(self.inputStack, mode)
def setNetworkGraph(self, findSkeleton=False):
# Network graph of the crowded region removed output
self.skeletonStack = self.inputStack
self.graph = get_networkx_graph_from_array(self.skeletonStack)
def setPrunedSkeletonOutput(self):
# Prune unnecessary segments in crowded regions removed skeleton
self.setNetworkGraph(findSkeleton=True)
self.outputStack = pr.getPrunedSkeleton(self.skeletonStack, self.graph)
saveStack(self.outputStack, self.path + "pruned/")
class Trabeculae (Skeleton):
pass
def TrabeculaeY (path):
path_mrb01_square = Trabeculae(path)
path_mrb01_square.setPrunedSkeletonOutput()
if __name__=='__main__':
path1 = (r' ')
path2 = (r' ')
path3 = (r' ')
the_list =[]
the_list.append(path1)
the_list.append(path2)
the_list.append(path3)
for i in range (0,len(the_list)):
p1 = multiprocessing.Process(target=TrabeculaeY, args=(the_list[i],))
p1.start()
p1.join()
继承对于多重处理来说不是问题
不能
join()
循环内的进程。这意味着循环要等到p1
完成它的工作,然后才能继续下一个循环相反,在循环中启动所有进程,然后在第二个循环中等待所有进程,如下所示:
我用于测试的完整代码:
相关问题 更多 >
编程相关推荐