This article describes the Python-based multi-process creation method for multiprocessing. Share to everyone for your reference. Specific as follows:
Import multiprocessingimport timedef Clock (interval): While True: print ("The time is%s"% time.time ()) Time.sleep (interval) if __name__== "__main__": p = multiprocessing. Process (target=clock,args= ()) P.start () #启动进程
Another way to define a process is to inherit the processes class and implement the Run method:
Import Multiprocessingimport Timeclass clockprocessing (multiprocessing. Process): def __init__ (self, intverval): multiprocessing. Process.__init__ (self) self.intverval = Intverval def run (self): when True: print ("The time is%s"% Time.time ()) Time.sleep (self.interval) if __name__== "__main__": p = clockprocessing (+) P.start () # Start process
Hopefully this article will help you with Python programming.