多进程入门
程序员文章站
2022-05-02 13:10:00
...
import multiprocessing
import time
def dance():
for i in range(3):
print("跳舞中...")
time.sleep(0.2)
def sing():
for i in range(3):
print("唱歌中...")
time.sleep(0.2)
if __name__ == '__main__':
multiprocessing.Process(target=dance).start()
multiprocessing.Process(target=sing).start()
执行结果:
跳舞中...
唱歌中...
跳舞中...
唱歌中...
跳舞中...
唱歌中...