一、进程:
1、语法
2、进程间通讯
3、进程池
二、Gevent协程
三、SelectPollEpoll异步IO与事件驱动
一、进程:
1、语法
1 简单的启动线程语法 2 def run(name): 3 time.sleep(2) 4 print("hello",name) 5 6 if __name__ == '__main__': 7 for i in range(10):同时启动10个进程 8 p = multiprocessing.Process(target=run,args=("bob",)) 9 p.start()
1 #进程里面再启动一个线程 2 #每个进程里面在启动一个线程 3 def thread_run(): 4 print('线程',threading.get_ident()) 5 6 def run(name): 7 time.sleep(2) 8 print("hello",name) 9 t = threading.Thread(target=thread_run,) 10 t.start() 11 12 13 if __name__ == '__main__': 14 for i in range(10): 15 p = multiprocessing.Process(target=run,args=("bob",)) 16 p.start()
1 from multiprocessing import Process 2 import os 3 4 5 def info(title): 6 print(title) 7 print('module name:', __name__) 8 print('parent process:', os.getppid()) 9 print('process id:', os.getpid()) 10 print(" ") 11 12 13 def f(name): 14 info('