from multiprocessing import Process
import time
class ClockPorcess(Process):
def __init__(self,value):
Process.__init__(self)
self.value=value
def run(self):
n=5
while n>0:
print(" The time is {}".format(time.ctime()))
time.sleep(self.value)
n-=1
#s使用自己的进程类创建进程对象
p=ClockPorcess(2)
#start后会自动执行run函数
p.start()
p.join()
自定义类
最新推荐文章于 2021-02-12 10:18:17 发布