V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
veezzz
V2EX  ›  Python

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

  •  
  •   veezzz · 2015-01-04 16:42:21 +08:00 · 3590 次点击
    这是一个创建于 3408 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在看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 条回复    2015-01-04 20:14:57 +08:00
    Missex
        1
    Missex  
       2015-01-04 17:23:40 +08:00   ❤️ 1
    epoll是有事件的时候或者超时才返回。
    aszxqw
        2
    aszxqw  
       2015-01-04 17:29:11 +08:00   ❤️ 1
    会。
    dndx
        3
    dndx  
       2015-01-04 17:56:12 +08:00   ❤️ 1
    可以阻塞也可以不阻塞。如果 timeout 是 -1,那么会一直等待直到最少一个 event available 或者被信号中断。

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

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

    http://man7.org/linux/man-pages/man2/epoll_wait.2.html
    zenliver
        4
    zenliver  
       2015-01-04 19:10:19 +08:00   ❤️ 1
    tornado的会, epoll自身可以立刻返回, 参考man
    inevermore
        5
    inevermore  
       2015-01-04 20:14:57 +08:00   ❤️ 1
    常规用法是会的。 而且用epoll的目的是,其他代码不阻塞,仅仅在epoll调用处阻塞。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2500 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:48 · PVG 22:48 · LAX 07:48 · JFK 10:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.