码迷,mamicode.com
首页 > 系统相关 > 详细

创建并开启子进程的两种方式2

时间:2018-02-07 21:29:36      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:proc   ini   tar   red   div   and   dom   int   imp   

#开进程的方法二:
import time
import random
from multiprocessing import Process


class Piao(Process):
    def __init__(self,name):
        super().__init__()
        self.name=name
    def run(self):
        print(%s piaoing‘ %self.name)

        time.sleep(random.randrange(1,5))
        print(%s piao end‘ %self.name)

p1=Piao(egon)
p2=Piao(alex)
p3=Piao(wupeiqi)
p4=Piao(yuanhao)

p1.start() #start会自动调用run
p2.start()
p3.start()
p4.start()
print(主线程‘)

创建并开启子进程的两种方式2

标签:proc   ini   tar   red   div   and   dom   int   imp   

原文地址:https://www.cnblogs.com/xiongrongqin/p/8428273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!