python(多进程multiprocessing、线程threading)

# Author: Sooele

import multiprocessing   #进程模块
import time,threading  #时间模块,线程模块

def thread_run():      #线程模块
    print("线程")


def run(name):#运行
    time.sleep(2)
    print('hello', name)
    t = threading.Thread(target=thread_run,)    
    t.start()


if __name__ == '__main__':   #进程模块
    for i in range(10): #循环
        p = multiprocessing.Process(target=run, args=('Sooele%s'%i,))
        #进程运行run,run里包括线程threading
        p.start()
  #  p.join()

发表评论