关于 epoll 的小小疑问, epoll 在等待事件的过程中会阻塞么

最近在看tornado的源码,有个RT的疑问

try:
    event_pairs = self._impl.poll(poll_timeout)
    except Exception as e:
    # Depending on python version and IOLoop implementation,
    # different exception types may be thrown and there are
    # two ways EINTR might be signaled:
    # * e.errno == errno.EINTR
    # * e.args is like (errno.EINTR, 'Interrupted system call')
        if errno_from_exception(e) == errno.EINTR:
            continue
        else:
            raise

在调用poll方法等待事件的过程中epoll是马上返回还是至少有一个事件后才返回

阅读 5.1k
2 个回答

epoll是至少有一个事件才返回。在有事件之前是阻塞住的

当然会阻塞啊

一般用法 while 1: fd.poll()
不阻塞不是死循环了?

当然有时候根据需要也有用非阻塞的(把超时设置成0),相当于是在查询系统事件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题