This article mainly introduces the multiprocessing-based multi-process creation method of python. The example analyzes the skills related to the operation process of the multiprocessing module, for more information about how to create a multiprocessing-based python multi-process, see the example in this article. 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.