multiprocessing pool -error从不成功的get中返回Dictionary

时间:2016-10-27 15:16:29

标签: python multiprocessing

所以要开始我从不平行处理任何东西......所以我不知道自己在做什么,不过我已经读了一些,而且我还有一个题。我的问题似乎最喜欢这篇文章How to do parallel programming in Python 我有两个功能需要一段时间并独立运行

# set dates to get data
d1 = DT.datetime(2015, 10, 1)
d2 = DT.datetime(2015, 10, 2)
# sets up a class to get various types of data from various places
gd = getdata(d1, d2)  
# both below return dictionary with unprocessed data
rawspec = gd.getwavespec(gaugenumber=0)  
rawwind = gd.getwind(gaugenumber=0)

目前,每个函数都独立运行,并返回一个包含数据的字典,每个函数大约需要1-5分钟。 (例如rawwind = {风速,方向,时间},rawspec = {时间,Hs,Tp,Tm,1D频谱,2D频谱等}})我想并行运行每个以加快我的工作流程中的数据准备。当我使用上述链接作为框架工作并尝试以下操作时,我收到TypeError: 'dict' object is not callable

的错误
from multiprocessing import Pool
pool = Pool()
result = pool.apply_async(gd.getwavespec(), ['gaugenumber=0'])
# here i get print statements that suggest the data are retrieved 

Data Gathered From Local Thredds Server

result.get(timeout=1000)  
Traceback (most recent call last):
    File "/home/spike/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-115-19dc220c614d>", line 1, in <module>
    result.get(timeout=100)
  File "/home/spike/anaconda2/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
TypeError: 'dict' object is not callable

当我通过result.successful()检查来电是否成功时我得到了False,当我从rawspec = gd.getwavespec(gaugenumber=0)运行<TextBox x:Class="CustomControls.MyFolder.CustomTextBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> </TextBox> 时,我不确定如何对此进行问题排查ipython控制台我获得了成功的回报,非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

不确定这是否有帮助,但我认为您正在调用apply_async错误。尝试从函数名称中删除括号(使用gd.getwavespec而不是gd.getwavespec())并发送元组。这只是一个愚蠢但有效的例子:

from multiprocessing import Pool
from time import sleep

def foo(a):
    print a
    sleep(2)

q = Pool(5)
q.apply_async(foo, args= (42,))
q.apply_async(foo, args= (43,))

sleep(10)