너무 helpfull하지 않은 다음 프로그램 :.
from multiprocessing import Process, Queue, current_process
import time
def f(q):
name = current_process().name
config = q.get()
print "%s got config: %s" % (name, config)
print "%s beginning processing at %s" % (name, time.asctime())
time.sleep(5)
print "%s completing processing at %s" % (name, time.asctime())
if __name__ == '__main__':
q = Queue()
processes = []
cfg = { 'my' : 'config', 'data' : 'here' }
for i in range(3):
p = Process(target=f, args=(q,))
processes.append(p)
p.start()
q.put(cfg)
for p in processes:
p.join()
인 (주 스크립트를 보여줍니다 " 다중 처리 관리자 ") 3 개의 프로세스를 생성하고 각각의 구성 (여기에 사전으로 표시)을 보냅니다.
각 프로세스는 구성을 읽으며 처리 (여기서는 5 초 동안 대기) 종료한다. 이 스크립트를 실행의 출력은 다음과 같습니다
Process-1 got config: {'my': 'config', 'data': 'here'}
Process-1 beginning processing at Tue Jun 23 23:34:23 2009
Process-2 got config: {'my': 'config', 'data': 'here'}
Process-2 beginning processing at Tue Jun 23 23:34:23 2009
Process-3 got config: {'my': 'config', 'data': 'here'}
Process-3 beginning processing at Tue Jun 23 23:34:23 2009
Process-1 completing processing at Tue Jun 23 23:34:28 2009
Process-2 completing processing at Tue Jun 23 23:34:28 2009
Process-3 completing processing at Tue Jun 23 23:34:28 2009
파이썬 문서는 일반적으로 도움이되지 D는 – johndodo