from threading import Thread
from multiprocessing import Process
import os

def work():
    print('Hello from ', os.getpid())

if __name__ == '__main__':
    #part1:在主进程下开启多个线程,每个线程都跟主进程的pid一样
    t1 = Thread(target = work)
    t2 = Thread(target = work)
    t1.start()
    t2.start()
    print('主线程/主进程pid',os.getpid())

    #part2:开多个进程,每个进程都有不同的pid
    p1=Process(target = work)
    p2=Process(target = work)
    p1.start()
    p2.start()
    print('主线程/主进程pid',os.getpid())
    '''
    【输出结果】:
    Hello from  2888
    Hello from  2888
    主线程/主进程pid 2888
    主线程/主进程pid 2888
    Hello from  3652
    Hello from  2076
    '''
