简体   繁体   English

pool.apply_async, pool.map 上相当复杂的 function

[英]pool.apply_async, pool.map on rather complicated function

I have a function that computes an approximation of KL divergence in higher dimensions.我有一个 function 计算更高维度的 KL 散度的近似值。 Inside, it uses sklearn.NearestNeighbors and calculations on np.arrays.在内部,它使用 sklearn.NearestNeighbors 和 np.arrays 上的计算。 Its called KLnn(P) where P.shape = (10000,2).它称为 KLnn(P),其中 P.shape = (10000,2)。 I want to apply it on many P inputs.我想将它应用于许多 P 输入。 [P0,P1,...]. [P0,P1,...]。 So I applied to test it on one input:所以我申请在一个输入上对其进行测试:

if __name__ == '__main__':
    with Pool() as p:
        res = p.apply_async(KLnn, (P,))
        print(res.get(timeout = 1))       

I get a timeout, and it's not causes by the calculation of the function, as the function call is far below 1 sec.我得到一个超时,这不是 function 的计算引起的,因为 function 调用远低于 1 秒。 So I tried:所以我尝试了:

if __name__ == '__main__':
    with Pool() as p:
        print(p.map(KLnn, [P]))
        p.close()
        p.join()

which then starts a deadlock.然后开始死锁。 In both cases, I would have expected that it just computes KLnn(P).在这两种情况下,我都希望它只计算 KLnn(P)。

Both code chunks were just grabbed from the multiprocessing docs.python example.这两个代码块都是从 multiprocessing docs.python 示例中获取的。

I found out that OS Windows 10 together with spyder is not suited for the multiprocessing package.我发现操作系统 Windows 10 和 spyder 不适合多处理 package。 This toy example and apply_async in a list comprehension works well in the cmd / anaconda prompt.这个玩具示例和列表理解中的 apply_async 在 cmd / anaconda 提示符下运行良好。 However, being new in the field of parallel processing it was not the first guess that the IDE / OS is the problem.然而,作为并行处理领域的新人,IDE / OS 并不是第一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM