相关疑难解决方法(0)

使用Python pool.map让多个进程对列表执行操作

我试图启动 6 个线程,每个线程从列表文件中获取一个项目,将其删除,然后打印该值。

from multiprocessing import Pool

files = ['a','b','c','d','e','f']

def convert(file):
    process_file = files.pop()
    print process_file

if __name__ == '__main__':

    pool = Pool(processes=6)
    pool.map(convert,range(6))
Run Code Online (Sandbox Code Playgroud)

预期输出应该是:

a
b
c
d
e
f
Run Code Online (Sandbox Code Playgroud)

相反,输出是:

f
f
f
f
f
f
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?提前致谢。

python threadpool

3
推荐指数
1
解决办法
9669
查看次数

标签 统计

python ×1

threadpool ×1