在创建我需要的实际应用程序之前,我试图对此有一个基本的了解.我最近从2.7移到了3.3.
从python文档直接复制粘贴此代码失败,这里稍微简单的示例也是如此.
这是我的代码,派生自第二个例子:
import concurrent.futures
nums = [1,2,3,4,5,6,7,8,9,10]
def f(x):
return x * x
# Make sure the map and function are working
print([val for val in map(f, nums)])
# Test to make sure concurrent map is working
with concurrent.futures.ProcessPoolExecutor() as executor:
for item in executor.map(f, nums):
print(item)
Run Code Online (Sandbox Code Playgroud)
这是输出:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "<module1>", line 13, in …Run Code Online (Sandbox Code Playgroud)