天天看点

python multiprocessing模块子进程函数传参

from multiprocessing import Process
from time timport *

def worker(sec,name):
	for i in range(3):
		sleep(sec)
		print('I am %s'%name)
		print('I am working...')

##方法1:使用 args=(xxx,xxx) 位置传参
#p = Process(target=worker,args=(2,'Levi'))

#方法2:使用kwargs={key1:value1,key2:value2...} 进行关键字传参
p = Process(target=worker,kwargs={'name':'Levi','sec':2})

p.start()
p.join()