我試圖使用python運行並行進程。我設法使用多處理模塊來做到這一點。在清除所有變量時在Python中進行並行處理
的問題是,當我在代碼的開頭添加一個「清除所有變量」,該算法使我這個錯誤:
Traceback (most recent call last):
File "", line 1, in runfile('C:/Users/cuca/Dropbox/USP/Pesquisa/PosQuali/Paralelo/Paraleltest2.py', wdir='C:/Users/cuca/Dropbox/USP/Pesquisa/PosQuali/Paralelo')
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/cuca/Dropbox/USP/Pesquisa/PosQuali/Paralelo/Paraleltest2.py", line 36, in answer1 = result1.get(timeout=1)
File "C:\Python27\lib\multiprocessing\pool.py", line 563, in get raise TimeoutError
TimeoutError
當我從刪除「清除所有變量」程序算法的開始,它的工作原理。
任何想法爲什麼?
謝謝。
#Clear All
all = [var for var in globals() if var[0] != "_"]
for var in all:
del globals()[var]
from multiprocessing import Pool
import math
def Func1(A):
for i in range(1000,100000):
R = A * math.cos(i) * math.cos(i)
return R
if __name__ == '__main__':
pool = Pool()
result1 = pool.apply_async(Func1, [2])
result2 = pool.apply_async(Func1, [4])
answer1 = result1.get(timeout=1)
answer2 = result2.get(timeout=1)