ThreapPool.map 不支持操作数类型异常,但映射不异常?
为什么内置映射可以工作,但多处理的 ThreadPool 映射却不能工作?
from multiprocessing.pool import ThreadPool
def identity(a, b): return (a, b)
map(identity, [1, 2, 3], [4, 5, 6])
p = ThreadPool(2)
#gives above error:
p.map(identity, [1, 2, 3], [4, 5, 6])
编辑: 经过一番挖掘,显然线程池的映射不支持 vararg 风格的映射,即 map(f, i1, i2, i3,...in) ,其中 i1 对应于 f 的第一个参数,i2 对应于第二个参数,依此类推。抛出异常是因为我给出的列表被解释为块大小或其他整数位置参数。
无论如何,简洁的解决方案将不胜感激。
Why does the built in map work but not multiprocessing's ThreadPool map work?
from multiprocessing.pool import ThreadPool
def identity(a, b): return (a, b)
map(identity, [1, 2, 3], [4, 5, 6])
p = ThreadPool(2)
#gives above error:
p.map(identity, [1, 2, 3], [4, 5, 6])
edit:
After some digging, apparently the thread pool's map does not support a vararg -style map, ie map(f, i1, i2, i3,...in) where i1 corresponds to the first argument of f, i2 the second, etc. The exception is thrown because the list I was giving it was being interpreted as the chunk size or some other integer positional argument.
Regardless, neat solutions would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输出
Output