sock.setblocking(0)
try:
data = sock.recv(1024)
except socket.error, e:
if e.args[0] == errno.EWOULDBLOCK:
print 'EWOULDBLOCK'
else:
if not data: #recv over
sock.close()
print 'close================='
else:
print 'recv ---data---------'
poem += data
以上所有代码都在一个循环中。使用non-blocking socket
(只想测试“非阻塞套接字”)来获取数据。但总是打印'EWOULDBLOCK',我不知道为什么?