V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jan 4, 2015 · 4559 views
    This topic created in 4136 days ago, the information mentioned may be changed or developed.

    最近在看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 replies    2015-01-04 20:14:57 +08:00
    Missex
        1
    Missex  
       Jan 4, 2015   ❤️ 1
    epoll是有事件的时候或者超时才返回。
    aszxqw
        2
    aszxqw  
       Jan 4, 2015   ❤️ 1
    会。
    dndx
        3
    dndx  
       Jan 4, 2015   ❤️ 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  
       Jan 4, 2015   ❤️ 1
    tornado的会, epoll自身可以立刻返回, 参考man
    inevermore
        5
    inevermore  
       Jan 4, 2015   ❤️ 1
    常规用法是会的。 而且用epoll的目的是,其他代码不阻塞,仅仅在epoll调用处阻塞。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2523 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 02:57 · PVG 10:57 · LAX 19:57 · JFK 22:57
    ♥ Do have faith in what you're doing.