io多路复用:用来检测多个socket对象是否有变化
socket_list = []
for i in [www.baidu.com.,.,.,.,.]
client = socket.socket()
client.setblocking(False)
#连接
try:
client.connect(("i",80)) #阻塞
except BlockingIOError as e:
print(e)
socket_list.append(client)
#事件循环
while true: #(检测)
r,w, e = select.select(socket_list,socket_list...,0.05)
#w [sk2,sk3], 连接成功了
for obj in w;
obj.send(‘get /http/1.0\...‘)
#r [sk2,sk3],可读
如果socket中返回内容了,表示可读,要收数据了
for obj in r:
response = obj.recv()
print(response)
总结
1.client.setblocking(false)
2,select.select() #检测:连接成功,数据回来