在使用 numpy 运行多处理时,我遇到了一个问题,Python 意外退出。我已经隔离了问题,因此我现在可以确认在运行以下代码时多处理工作正常:
import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p
def test(args):
x,i = args
if i == 2:
time.sleep(4)
arr = np.dot(x.T,x)
print i
if __name__ == '__main__':
x = np.random.random(size=((2000,500)))
evaluations = [(x,i) for i in range(5)]
p = Pool()
p.map_async(test,evaluations)
p.close()
p.join()
当我尝试评估下面的代码时会出现问题。这使得 Python 意外退出:
import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p
def test(args):
x,i = args
if i == 2:
time.sleep(4)
arr = np.dot(x.T,x)
print i
if __name__ == '__main__':
x = np.random.random(size=((2000,500)))
test((x,4)) # Added code
evaluations = [(x,i) for i in range(5)]
p = Pool()
p.map_async(test,evaluations)
p.close()
p.join()
请帮助某人。我愿意接受所有建议。谢谢。注意:我尝试了两台不同的机器,都出现了同样的问题。