상세 컨텐츠

본문 제목

[파이썬(Python)] #21. 멀티프로세싱 ( multiprocessing )

python

by 빨간눈동자 2021. 8. 20. 14:00

본문

반응형
# test.py

import os
from multiprocessing import Process, current_process

def worker(num):
    ret = num * 2
    name = current_process().name
    print(f'{num} * 2 = {ret} by {name} process')

if __name__ == "__main__" :
    process_name = ['A', 'B', 'C', 'D']
    procs = []

    for index, number in enumerate(process_name):
        proc = Process(target=worker, args=(number, ))
        procs.append(proc)
        proc.start()

    proc = Process(target=worker, name='Test', args=(2, ))
    proc.start()
    procs.append(proc)

    for proc in procs:
        proc.join()

반응형

관련글 더보기