Python multiprocessing-Based Multi-Process Creation Method
This example describes how to create a multiprocessing-based python multi-process. Share it with you for your reference. The details are as follows:
?
| 1 2 3 4 5 6 7 8 9 |
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 () # start the process |
Define another method of the Process, inherit the Process class, and implement the run method:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
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 () # start the process |
I hope this article will help you with Python programming.