python 套接字对 EINTR 有何作用?
到目前为止,我的网络代码工作正常,但我有点担心我隐藏在地毯下的东西:
accept
、close
、connect< 的手册页/code>、
recv
和 send
提到,当系统调用被信号中断时,errno.EINTR
会显示出来。
我在这里很无知。
python 用它做什么?它是否会自动重试调用,是否会引发带有 errno 的 socket.error ?如果引发该异常,我应该做什么?我可以在单元测试中自己生成这些信号吗?
So far my networking code works fine, but I'm a bit worried about something I hid under the carpet:
The man pages for accept
, close
, connect
, recv
and send
mention that errno.EINTR
can show up when a system call was interrupted by a signal.
I am quite clueless here.
What does python do with that ? Does it automatically retry the call, does it raise a socket.error with that errno ? What is the appropriate thing I should do if that exception is raised ? Can I generate these signals myself in my unittests ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 只是重试调用并对用户隐藏信号(有助于在 -EINTR 不存在的情况下实现跨平台一致性)。您可以放心地忽略 EINTR 问题,但如果您想测试它,也很容易做到。只需设置一个不会返回的阻塞操作(例如没有传入连接的 socket.accept)并向进程发送信号。
Python simply retries the call and hides the signal from the user (helps with cross-platform consistency where -EINTR doesn't exist). You can safely ignore the EINTR issue but if you'd like to test it anyway, it's easy to do. Just set up a blocking operation that will not return (such as a socket.accept with no incoming connection) and send the process a signal.