在python中,我的线程拆分速度不够快

在python中,我的线程拆分速度不够快,python,multithreading,scikit-learn,histogram,Python,Multithreading,Scikit Learn,Histogram,我正试图加快我的hog传输速度,但似乎添加的线程越多,它得到的帮助就越慢??? def worker(patches): return [feature.hog(patch) for patch in patches] 这就是功能 segment_split, segment_index, threads = 4, 0, [] segment_jump = len(patches) / segment_split segment_list = [] for i in range(seg

我正试图加快我的hog传输速度,但似乎添加的线程越多,它得到的帮助就越慢???

def worker(patches):
    return [feature.hog(patch) for patch in patches]
这就是功能

segment_split, segment_index, threads = 4, 0, []
segment_jump = len(patches) / segment_split
segment_list = []
for i in range(segment_split):
    segment_list.append(patches[int(segment_index):int(segment_index+segment_jump)])
    segment_index += segment_jump

pool = multiprocessing.Pool()
lis = pool.map(worker, segment_list)
tmp = []
for x in lis:
    tmp.extend(x)

线程用于并发,而不是并行。由于全局解释器锁,Python一次只能运行一个线程。如果
worker
是CPU密集型的,线程将不会加快速度-您需要多处理。您好,但我尝试了多处理,但得到了内存共享堆栈。您能帮我吗?具体取决于您被卡住的位置。你有什么错误吗?我使用了Pool Thechnice,但它看起来仍然很慢…它“看起来很慢”吗?或者你有实际的数字表明,多处理代码需要更多的时间来完成与单线程代码相同的任务?线程是为了并发性,而不是并行性。由于全局解释器锁,Python一次只能运行一个线程。如果
worker
是CPU密集型的,线程将不会加快速度-您需要多处理。您好,但我尝试了多处理,但得到了内存共享堆栈。您能帮我吗?具体取决于您被卡住的位置。您是否有任何错误?我使用了Pool Thechnice,但它仍然看起来很慢…它是否“看起来很慢”,或者您有实际的数字表明,使用多处理的代码需要更多的时间来完成与单线程代码相同的任务?