python 多进程multiprocessing

 

from multiprocessing import Process
import time

def print_time(threadName, delay, iterations):
    start = int(time.time())
    for i in range(0,iterations):
        time.sleep(delay)
        seconds_elapsed = str(int(time.time()) - start)
        print (threadName if threadName else seconds_elapsed)


processes = []
processes.append(Process(target=print_time, args=(None, 1, 10)))
processes.append(Process(target=print_time, args=("Fizz", 3, 3)))
processes.append(Process(target=print_time, args=("Buzz", 5, 3)))

for p in processes:
    p.start()

for p in processes:
    p.join()
    
print("Program complete")

 

posted @ 2019-06-20 20:48  anobscureretreat  阅读(123)  评论(0编辑  收藏  举报