저는 멀티 프로세싱을 연구 중이며 웹 사이트에서이 예제를 사용했습니다. 그러나 내 MacBook 망에서이 예제를 실행하려고해도 아무런 변화가 없습니다. 다음은 예였다멀티 프로세싱을 사용할 때 process.join을 스크립트에 넣으면 파이썬이 충돌합니다.
그것은 내가 'list_append'기능으로 인쇄 문을 넣어 후에 나오는 것에 따라import random
import multiprocessing
def list_append(count, id, out_list):
"""
Creates an empty list and then appends a
random number to the list 'count' number
of times. A CPU-heavy operation!
"""
for i in range(count):
out_list.append(random.random())
if __name__ == "__main__":
size = 10000000 # Number of random numbers to add
procs = 2 # Number of processes to create
# Create a list of jobs and then iterate through
# the number of processes appending each process to
# the job list
jobs = []
for i in range(0, procs):
out_list = list()
process = multiprocessing.Process(target=list_append,
args=(size, i, out_list))
jobs.append(process)
# Start the processes (i.e. calculate the random number lists)
for j in jobs:
j.start()
# Ensure all of the processes have finished
for j in jobs:
j.join()
print ("List processing complete.")
는, 아무것도 인쇄하지 않기 때문에 문제는 실제로 j.join()
오히려 j.start()
비트 아닙니다.
왜 프로세스를 생성, 시작 및 결합하는 데 별도의 루프가 있습니까? – corn3lius
@ Corn3lius - 필자는 온라인에서 찾은 예제에서 문자 그대로 복사하여 붙여 넣었지만 그렇지 않은 경우에는 루프에서 빼내려고했습니다. 그러나 똑같은 문제가 발생했습니다. –