Process(target=函数名,args=(),name,kwargs)
target:加进程调用的函数名,一般不加括号
name:进程的名字
kwargs:字典参数
args:元组参数,如果参数就一个,记得加逗号’,’
import threading
import time
from multiprocessing import Process
def sing():
for i in range(1,5):
print('正在场地%d首歌'%i)
time.sleep(0.4)
def dance():
for i in range(1,5):
print('正在跳第%d场舞蹈'%i)
time.sleep(0.4)
if __name__ == '__main__':
p1=Process(target=sing,name='sing')
p2=Process(target=dance,name='dance')
p1.start()
p2.start()
dance()