【发布时间】:2017-05-29 11:49:31
【问题描述】:
我第一次在 Python 中尝试多线程。我看到documentation here。以下是我的示例代码
from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool(4)
mylist = [3,4,5,6,7,8, ..., 5]
results = pool.map(my_method, my_list) # from docs it is clear that pool.map takes method and argument as a list
def my_method(mylist):
data = []
for i in range (len(mylist)):
# do something using mylist = subdata
data.append(subdata)
return data
返回如下错误
Traceback (most recent call last):
File "C:/Users/algorithm.py", line 30, in my_method
for i in range (len(mylist)):
TypeError: object of type 'float' has no len()
从文档中可以清楚地看出pool.map 具有函数和列表(see this tutorial too),但为什么将my_list 假设为float 会给出此错误。有什么建议么 ?谢谢
【问题讨论】:
标签: python multithreading threadpool