This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
def calc(a,b) : | |
return a*b+1 | |
if __name__ == '__main__': | |
with Pool(processes=16) as p: | |
res = [p.apply_async(calc, args=(i,2)) for i in range(20)] | |
result = [r.get() for r in res] | |
print(result) |
병렬처리시, if __name__ == '__main__' : 으로 한번 분기하는게 필요한데, 그렇지않으면 프로세스가 계속 내부적으로 뭔가를 불러대서 무한루프가 돈다.
'데이터분석 > Code & Tools & Script Snippet' 카테고리의 다른 글
numpy array - stack 참조 행렬합치기 (0) | 2018.10.09 |
---|---|
kalman script (0) | 2018.06.09 |
Error in plotting with ggplot (0) | 2018.05.27 |
Swift 4 - Read CGImage File (0) | 2018.05.17 |
모델평가 smape 파일창고 (0) | 2018.04.22 |