楚阿旗

博客园 首页 新随笔 联系 订阅 管理
import multiprocessing as mp
import time

def name_and_time(name,num):
    print(f"Hello {name}, current time is {time.time()} ({num})")
    print('Sleeping for 2 seconds ...')
    time.sleep(2)
    print("After sleeping ... exiting function")


if __name__ == '__main__':
    process_list = list()

    for i in range(100):
        process = mp.Process(target=name_and_time,args=('Andrei',i))
        process_list.append(process)

    for p in process_list:
        p.start()

    for p in process_list:
        p.join()
        
    print('Other instructions of the main module....')
    print('End of Script')

 

posted on 2020-01-27 10:42  楚阿旗  阅读(140)  评论(0)    收藏  举报