socket.error errno.EWOULDBLOCK
我正在阅读一些代码,并且遇到了这一行,
socket.error errno.EWOULDBLOCK
任何人都可以告诉我引发此错误的条件是什么?
i'm reading some code and i've come across this line
socket.error errno.EWOULDBLOCK
can anyone tell me what the conditions have to be to raise this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自Python的套接字模块: http://docs.python.org/library/socket.html
它引用的错误异常是 errno.EWOULDBLOCK
要发生这种情况,必须使用以下方法将套接字对象设置为非阻塞模式:
socketObj.setblocking(0)
From Python's socket module: http://docs.python.org/library/socket.html
The error exception it's referring to is errno.EWOULDBLOCK
For this to happen, the socket object must be set to non-blocking mode using:
socketObj.setblocking(0)
请注意,EWOULDBLOCK 的错误号为 11:
相关的错误消息为:
这是一些显示 EWOULDBLOCK 错误的玩具代码。
它设置一个服务器和客户端,尝试通过套接字连接相互通信。当调用
s.setblocking(0)
将套接字置于非阻塞模式时,对s.recv
的后续调用将引发socket.error.我认为发生这种情况是因为连接的两端都试图接收数据:
如果
s.setblocking(0)
被注释掉,您应该看到Note that EWOULDBLOCK is error number 11:
And the associated error message is:
Here is some toy code which exhibits the EWOULDBLOCK error.
It sets up a server and client which try to talk to each other over a socket connection. When
s.setblocking(0)
is called to put the socket in non-blocking mode, a subsequent call tos.recv
raises thesocket.error
. I think this happens because both ends of the connection are trying to receive data:If
s.setblocking(0)
is commented-out, you should see