时间:2021-07-01 10:21:17 帮助过:75人阅读
import multiprocessing import time def clock(interval): while True: print ("the time is %s"% time.time()) time.sleep(interval) if __name__=="__main__": p = multiprocessing.Process(target=clock,args=(15,)) p.start() #启动进程
定义进程的另一种方法,继承Process类,并实现run方法:
import multiprocessing import time class ClockProcessing(multiprocessing.Process): def __init__(self, intverval): multiprocessing.Process.__init__(self) self.intverval = intverval def run(self): while True: print ("the time is %s"% time.time()) time.sleep(self.interval) if __name__=="__main__": p = ClockProcessing(15) p.start() #启动进程
希望本文所述对大家的Python程序设计有所帮助。