<pre class="python">```
#方法一 直接调用
import time
import random
from multiprocessing import Process
def run(name):
   index = 0
   for i in range(3):
       print('%s runing' %name)
       time.sleep(random.randrange(1,5))
       print('%s running end' %name)
       index +1

l = []
if __name__ == "__main__":
   for i in range(20):
       p = Process(target=run,args=(i,))
       p.start()
       l.append(p)
   for proc in l:
       proc.join()
   print("执行完毕")

标签: index, 进程, python, import, random, name, print

相关文章推荐

添加新评论,含*的栏目为必填