day_6.16网络编程

单线程服务器select版:

select ---->最多1024个

poll ----->解决了套接字上限的问题----->轮询检测

  

 关于 sys模块:

通过fd找套接字

 协程:

#!--*--coding:utf-8 --*--
# 2018-6-16 20:14:02
# 创建一个简单的协程
'''
不知道为毛线运行不了
2018-6-16 20:41:09
明天父亲节,后天端午!!!
要专心看python!!!
你决定不了日出时间,但可以决定自己起床时间!
有的人拼命浪费时间!有的人拼命争时间!!
'''
# import time

# def A():
#     while True:
#         print("----A---")
#         #执行到yield就停,调用next()后继续执行
#         yield 
#         time.sleep(0.5)

# def B(c):
#     while True:
#         print("----B---")
#         c.next()
#         time.sleep(0.5)

# if __name__=='__main__':
#     a = A()    #生成器
#     B(a) 

# 用greenlet创建协程 
#使用greenlet时候 需要 pip install greenlet

from greenlet import greenlet
import time
def test1():
    while True:
        print("----A----")
        gr2.swith()
        time.sleep(0.5)

def test2():
    while True:
        print("-----B-----")
        gr1.swith()
        time.sleep(0.5)

gr1 = greenlet(test1)
gr2 = greenlet(test2)


#切换到gr1中运行
gr1.swith()
原文地址:https://www.cnblogs.com/zhen1996/p/9191162.html