python-非阻塞IO
Posted benchdog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-非阻塞IO相关的知识,希望对你有一定的参考价值。
client端:
# import time # import socket # sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # # while True: # sk.connect((‘127.0.0.1‘,6667)) # print("hello") # sk.sendall(bytes("hello","utf8")) # time.sleep(2) # break
server端:
# import time # import socket # sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # sk.bind((‘127.0.0.1‘,6667)) # sk.listen(5) # sk.setblocking(False) # print (‘waiting client connection .......‘) # while True: # try: # # connection,address = sk.accept() # 进程主动轮询 # print("+++",address) # client_messge = connection.recv(1024) # print(str(client_messge,‘utf8‘)) # connection.close() # except Exception as e: # print (e) # time.sleep(4)
以上是关于python-非阻塞IO的主要内容,如果未能解决你的问题,请参考以下文章
python开发IO模型:阻塞&非阻塞&异步IO&多路复用&selectors
python开发IO模型:阻塞&非阻塞&异步IO&多路复用&selectors