Python multi-process creation method based on multiprocessing, python multi-process
This example describes how to create a multiprocessing-based python multi-process. Share it with you for your reference. The details are 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 = (15,) p. start () # start the process
Define another method of the Process, inherit the Process 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): while True: print ("the time is % s" % time. time () time. sleep (self. interval) if _ name __= = "_ main _": p = ClockProcessing (15) p. start () # start the process
I hope this article will help you with Python programming.