进程池线程池/协程/io模型

进程池线程池

协程

 

from gevent import monkey;monkey.patch_all()
import gevent,time

def eat(name):
    print('%s eat 1'%name)
    time.sleep(2)
    print('%s eat 2'%name)

def play(name):
    print('%s play 1'%name)
    time.sleep(1)
    print('%s play 2'%name)

g1=gevent.spawn(eat,'egon')
g2=gevent.spawn(play,name='egon')
g1.join()
g2.join()
print('主')

结果是:
egon eat 1
egon play 1
egon play 2
egon eat 2
主

 

 

io模型

上一篇:【NOIP2018】赛道修建


下一篇:shell编程===》shell解释器交互式环境、shell队列实现线程并发控制