首页 > 技术文章 > [Python]Running multiprocessing

jbite9057 2020-01-27 10:42 原文

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')

 

推荐阅读