进程和线程的开启效率
code
from threading import Thread from multiprocessing import Process import os def work(name): print('{} say hello'.format(name)) if __name__ == '__main__': # 在主进程下开启线程 t=Thread(target=work,args=("thread",)) t.start() print('主线程/主进程') # 在主进程下开启子进程 t=Process(target=work,args=("progress",)) t.start() print('主线程/主进程')
Outputs
macname@MacdeMacBook-Pro py % python3 cccccc.py thread say hello 主线程/主进程 主线程/主进程 progress say hello macname@MacdeMacBook-Pro py %