[python] OS에 따른 MultiProcessing 코드 구현시 주의해야 할 점

최승언·2022년 10월 26일
0

python

목록 보기
3/22

window로 구현할 때는 아래 예시처럼 if __name__ == '__main__': 문에 freeze_support() 를 넣어주어야 멈추지 않는다.

# for window
from multiprocessing import Process, freeze_support

def f():
    print('hello world!')

if __name__ == '__main__':
    freeze_support()
    Process(target=f).start()

리눅스로 multiprocessing Pool을 구현할 시 아래 코드로 import 하면 멈추지 않는다.

# for linux
import multiprocessing.pool import ThreadPool as Pool
profile
작업하다가 막힌부분을 기록하는 곳.

0개의 댓글