标签:imp color class main time tar sssss code multi
1 import multiprocessing,time 2 def f1(): 3 time.sleep(3) 4 print(‘ssss‘) 5 6 def f2(): 7 time.sleep(3) 8 print(‘sssssss‘) 9 10 if __name__ == ‘__main__‘: 11 p1 = multiprocessing.Process(target=f1,) 12 p2 = multiprocessing.Process(target=f2,) 13 p1.start() 14 p2.start() 15 16 # f1() 17 # f2()
运行结果为在3秒后显示:
ssss
sssssss
两个进程并发,遇到IO时切换,切换速度快,形成几乎三秒完成两个进程的错觉。
标签:imp color class main time tar sssss code multi
原文地址:https://www.cnblogs.com/shachengcc1/p/11306162.html