1. 程式人生 > >寫面向對象的新Process

寫面向對象的新Process

self sin bsp star func ini init alt image

import multiprocessing

class mypro(multiprocessing.Process):

  def __init__(self,a,b):
    super().__init()__      原生的Process裏面的許多函數需要原生構造函數初始化  

     self.a = a

     self.b = b

  def run(self):      相當於實現原來target=func函數裏面的功能,原生的start函數中會自動調用run方法

    print(self.a + self.b)

A = mypro(4,5)

A.start()

圖例:

    技術分享圖片

寫面向對象的新Process