我想将一些JSON对象和两个整数传递给一个池。Python TypeError - 所需的类似字节的对象,而不是str
for i in range(0, multiprocessing.cpu_count()-1):
fromindex = i * chunklen
toindex = (i+1) * chunklen
chunkedData.append([data['features'][fromindex:toindex], weekdaytopredict, hourtopredict])
chunkedData.append([data['features'][toindex:], weekdaytopredict, hourtopredict])
parallelstart = time.time()
result = (pool.map(parallelUpdateWithDT, chunkedData))
data
是带有一些多边形的geoJSON文件。我想分发这些多边形进行并行处理。我将n/cpu_count()
多边形传递给parallelUpdateWithDT
函数,该函数应该进一步处理它们。我的问题是typeerror:即使print(chunkedData)
返回<class 'list'>
,我geth以下错误:TypeError: a bytes-like object is required, not 'str'
。我在哪里搞砸了?完整堆栈跟踪:
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "<ipython-input-114-bf56cacb90b9>", line 34, in parallelUpdateWithDT
if('rain' in result):
TypeError: a bytes-like object is required, not 'str'
"""
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-115-031a5e24ee66> in <module>()
----> 1 decisionTreePrediciton(3, 5)
<ipython-input-114-bf56cacb90b9> in decisionTreePrediciton(weekdaytopredict, hourtopredict)
15 print (type(chunkedData))
16
---> 17 result = (pool.map(parallelUpdateWithDT, chunkedData))
18 parallelend = time.time()
19
/usr/lib/python3.5/multiprocessing/pool.py in map(self, func, iterable, chunksize)
258 in a list that is returned.
259 '''
--> 260 return self._map_async(func, iterable, mapstar, chunksize).get()
261
262 def starmap(self, func, iterable, chunksize=None):
/usr/lib/python3.5/multiprocessing/pool.py in get(self, timeout)
606 return self._value
607 else:
--> 608 raise self._value
609
610 def _set(self, i, obj):
的chunkedData
样本:
[[[{'geometry': {'coordinates': [[[10.914622377957983, 45.682007076150505], [10.927456267537572, 45.68179119797432], [10.927147329501077, 45.672795442796335], [10.914315493899755, 45.67301125363092], [10.914622377957983, 45.682007076150505]]], 'type': 'Polygon'}, ///////////////////////etc, waaay too big////////////, 'id': 6574, 'properties': {'cellId': 11454}}], 3, 5]
这是怎么一个str
?我不明白。谢谢你的帮助!
工作人员在'if('rain'in结果):'并将其传播给父母并在那里重新提出,让其知道发生了什么。问题在于这里没有发布的工作者代码。我猜'结果'是一个不在块中的计算值。您可以在该行的上方添加“print(repr(result))”,并查看您获得的内容。但是由于这个错误代码没有发布,所以我们不能说太多。 – tdelaney