我正在尝试使用多处理模块并行化Python 2.7中的函数。不幸的是,在我的pool函数中,当传递多个参数时,我似乎遇到了错误。我试图将它们打包为元组列表,作为一个类,以及列表列表,所有似乎都给我以下错误:
File "plot_gfs.py", line 132, in plot_data
results = pool.map(plot_var,args)
File "/opt/Python2.7/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "/opt/Python2.7/lib/python2.7/multiprocessing/pool.py", line 558, in get
raise self._value
AttributeError: 'str' object has no attribute 'name'
这是我的并行功能代码:
def plot_data(lats, lons, bounds):
lons2, lats2 = np.meshgrid(lons, lats)
x, y = basem(lons2, lats2)
pool = mp.Pool(4)
args = [('prmslmsl', 0, 'jet', 950, 1050, i, x, y, bounds)
for i in range(80)]
results = pool.map(plot_var, args)
pool.close()
pool.join()
注意:plot_var函数标记是:
def plot_var(var_in):
答案 0 :(得分:1)
尝试将参数作为元组传递:
file: lines+ EOF
;
lines: data_line
| text_line
;
text_line: TEXT TEXTUALDATA
;
data_line: DATA sensordata
;
sensordata: DATA FLOATVALUE PERIOD
;
TEXT:'TEXT';
DATA: 'DATA' ->mode(SENSORMODE);
TEXTUALDATA: (.)*?
;
mode SENSORMODE;
FLOATVALUE: ([0-9])*('.')([0-9])*
;
WS:[ \t]->skip
;
WS2:[\r\n]
;
PERIOD:'.' ->mode(DEFAULT_MODE)
;
或者,根据您的使用情况:
results = pool.map(plot_var, (args))