方式一(常用):

from multiprocessing import Process
import time

def task(x):
    print('%s is ruuning' %x)
    time.sleep(3)
    print('%s is done' %x)


if __name__ == '__main__':
    # Process(target=task,kwargs={'x':'任务1'})
    p=Process(target=task,args=('任务1',))
    p.start() # 只是给操作系统发送一个开启子进程的信号
    print('主')

  

方式二:

from multiprocessing import Process
import time

class MyProcess(Process):
    def __init__(self,name):
        super().__init__()
        self.name=name

    def run(self):
        print('%s is ruuning' %self.name)
        time.sleep(3)
        print('%s is done' %self.name)

    def func(self):
        print('new func')

if __name__ == '__main__':
    p=MyProcess('egon')
    p.start() # 只是给操作系统发送一个开启子进程的信号
    print('主')

    p.func()