我试图使用多处理运行一个简单的测试.测试工作正常,直到我导入numpy(即使它没有在程序中使用).这是代码:
from multiprocessing import Pool
import time
import numpy as np #this is the problematic line
def CostlyFunc(N):
""""""
tstart = time.time()
x = 0
for i in xrange(N):
for j in xrange(N):
if i % 2: x += 2
else: x -= 2
print "CostlyFunc : elapsed time %f s" % (time.time() - tstart)
return x
#serial application
ResultList0 = []
StartTime = time.time()
for i in xrange(3):
ResultList0.append(CostlyFunc(5000))
print "Elapsed time (serial) : ", time.time() - StartTime
#multiprocessing …Run Code Online (Sandbox Code Playgroud) 我不明白为什么copy.deepcopy不修改对象的id:
import copy
a = 'hello world'
print a is copy.deepcopy(a) # => True ???
Run Code Online (Sandbox Code Playgroud)