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

2015-01-04 16:42:21 +08:00
 veezzz

最近在看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是马上返回还是至少有一个事件后才返回

3633 次点击
所在节点    Python
5 条回复
Missex
2015-01-04 17:23:40 +08:00
epoll是有事件的时候或者超时才返回。
aszxqw
2015-01-04 17:29:11 +08:00
会。
dndx
2015-01-04 17:56:12 +08:00
可以阻塞也可以不阻塞。如果 timeout 是 -1,那么会一直等待直到最少一个 event available 或者被信号中断。

如果 timeout 是 0,那么会立刻返回,即使没有可用 event。

如果 timeout 是其他数字,那么会最多等待这么多秒,除非有至少一个 event available 或者被信号中断。

http://man7.org/linux/man-pages/man2/epoll_wait.2.html
zenliver
2015-01-04 19:10:19 +08:00
tornado的会, epoll自身可以立刻返回, 参考man
inevermore
2015-01-04 20:14:57 +08:00
常规用法是会的。 而且用epoll的目的是,其他代码不阻塞,仅仅在epoll调用处阻塞。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/159115

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX